これが消去の警告を出す理由を誰かが説明できますか?
def optionStreamHead(x: Any) =
x match {
case head #:: _ => Some(head)
case _ => None
}
与えます:
warning: non variable type-argument A in type pattern scala.collection.immutable.Stream[A] is unchecked since it is eliminated by erasure
case head #:: _ => Some(head)
このケースを書いてif (x.isInstanceOf[Stream[_]]) ...
も警告が表示されないことはわかっていますが、私の場合、実際にはパターン マッチングを使用したいのですが、理解できない警告がたくさんあるのは悪いようです。
そして、ここに同様に不可解なケースがあります:
type IsStream = Stream[_]
("test": Any) match {
case _: Stream[_] => 1 // no warning
case _: IsStream => 2 // type erasure warning
case _ => 3
}