我有一个自递归类型:
trait Problem[P <: Problem[P]] {
type Solution
}
现在,我想在P#Solution
. 假设我们在case class Foo[P <: Problem[P]]()
:
case ExampleCaseClass(s: P#Solution) if conditionApplies() =>
// do sth
case ExampleCaseClass(s: P#Solution) =>
// now sth else
当然,由于类型擦除而失败。有没有办法让代码在 scala 中编译?
我见过类/类型标签,但我不确定它们是否可以在这种情况下使用。