定义空特性测试:
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)