小编Yur*_*riy的帖子

复合类型的案例类伴随对象生成错误

定义空特性测试:

trait Test
Run Code Online (Sandbox Code Playgroud)

复合型中使用的是什么:

scala> val a : Int with Test = 10.asInstanceOf[Int with Test]
a: Int with Test = 10
Run Code Online (Sandbox Code Playgroud)

和带有复合类型参数的case类(如Unboxed Tagged Type):

scala> case class Foo(a: Int with Test)
error: type mismatch;
 found   : Double
 required: AnyRef
Note: an implicit exists from scala.Double => java.lang.Double, but
methods inherited from Object are rendered ambiguous.  This is to avoid
a blanket implicit which would convert any scala.Double to any AnyRef.
You may wish to use a type ascription: `x: java.lang.Double`. …
Run Code Online (Sandbox Code Playgroud)

scala case-class compound-type

10
推荐指数
1
解决办法
588
查看次数

标签 统计

case-class ×1

compound-type ×1

scala ×1