【发布时间】:2016-09-04 14:39:15
【问题描述】:
我有一个自递归类型:
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 中编译?
我见过类/类型标签,但我不确定它们是否可以在这种情况下使用。
【问题讨论】:
标签: scala generics types type-erasure scala-generics