相关疑难解决方法(0)

结构细化中的结果类型可能不引用用户定义的值类

当我将包装器定义为值类(扩展AnyVal)时:

class Wrapper(val string: String) extends AnyVal

def wrapperHolder(w: Wrapper): {def wrapper: Wrapper} = new {
  def wrapper: Wrapper = w
}
Run Code Online (Sandbox Code Playgroud)

我对于wrapperHolder有以下编译错误:

Error:(5, 22) Result type in structural refinement may not refer to a user-defined value class
def wrapper: Wrapper = w
Run Code Online (Sandbox Code Playgroud)
  • 为什么它不适用于价值类?

scala compiler-errors compilation structural-typing value-class

6
推荐指数
1
解决办法
260
查看次数