3

我在 scala 函数中有以下模式匹配案例:

def someFunction(sequences: Iterable[Seq[Int]]):Seq[Int] = sequences match{
    case Seq() => Seq(1)
    case _ => ...
    ...
}

我收到以下警告:

warning: non variable type-argument A in type pattern Seq[A] is unchecked since it is eliminated by erasure
case Seq(_) => Seq(1)
        ^
one warning found

这是什么意思?

4

1 回答 1

2

这个警告有点虚假,在 Scala 2.10 上不会出现。事实上,我认为这是 Scala 2.8 的回归(也就是说,它不存在于那里)。

警告的原因是它解释Seq(_)为 mean Seq(_: Seq[Int]),因为这是 的类型参数sequences,然后抱怨它不能保证在Int那里,因为在编译时,它将被删除。正如我所说,这是虚假的。

于 2012-06-12T23:50:25.807 回答