scala> class Foo[T <: Comparable[T]](val x : T)
defined class Foo
scala> (3: Int).asInstanceOf[Comparable[Int]]
res60: java.lang.Comparable[Int] = 3
scala> new Foo(3)
<console>:13: error: inferred type arguments [Int] do not conform to class Foo's type parameter bounds [T <: java.lang.Comparable[T]]
new Foo(3)
^
Run Code Online (Sandbox Code Playgroud)
第二个表达式是类型擦除的结果吗?
我将如何定义Foo以便我可以使用Int对其进行参数化,但仍然能够使用其实例变量执行某些排序行为?