Scala编译错误:未找到:类型_$1

我正在研究 Scala 中的存在类型2.12.x。为此,我正在测试以下代码:

trait Parent
class ChildA extends Parent
class ChildB extends Parent

def whatIsInside(opt: Option[_ <: Parent]): String = {
  opt match {
    case _: Option[_ <: ChildA] => "ChildA"
    case _: Option[_ <: ChildB] => "ChildB"
    case _                      => throw new IllegalArgumentException("unknown type")
  }
}


whatIsInside(Some(new ChildA))

由于类型擦除,我不希望这在运行时起作用,但是这甚至无法编译。我收到以下错误:

[error] ExistentialTypes.scala:12:24: not found: type _$2
[error]         case _: Option[_ <: ChildA] => "ChildA"
[error]                        ^
[error] ExistentialTypes.scala:13:24: not found: type _$3
[error]         case _: Option[_ <: ChildB] => "ChildB"
[error]                        ^

有人可以解释这些错误吗?

以上是Scala编译错误:未找到:类型_$1的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>