【发布时间】:2011-03-07 18:37:12
【问题描述】:
看看这个 Scala 类:
class Example {
val (x, y): (Int, Int) = (1, 2)
}
编译它会导致警告:
Example.scala:2: warning: non variable type-argument Int in type pattern
(Int, Int) is unchecked since it is eliminated by erasure
val (x, y): (Int, Int) = (1, 2)
^
删除显式类型注释可以消除此警告:
class Example {
val (x, y) = (1, 2)
}
为什么我会收到警告,为什么删除显式类型注释会摆脱它?据我所知,没有什么真正的变化,x 和 y 仍然是 Int 类型,没有类型注释。
【问题讨论】:
标签: scala compiler-warnings type-erasure