我目前正在研究Scala中的A*实现.为了实现一个干净的结构,我想使用一个嵌套的case类结构,它实现了一个自我限制的特征.但是,在Scala IDE中实现它时遇到了一些问题.以下代码将无法编译:
trait A[T <: A[T]]
class B {
case class C(int: Int) extends A[C] // A[this.C] won't work either
def make = C(5)
}
object D {
def foo[T <: A[T]](some: T) = {}
val c = new B().make
foo(c) // this does not compile
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以使这个结构有效吗?