【发布时间】:2016-03-14 05:51:45
【问题描述】:
当我这样做时
val oldId :Long = 123;
val i = 1
val newId = (oldId: @switch) match {
case 1 => 1234
case 2 => 5678
case 3 => 1122
case 4 => 3344
}
我收到编译器警告
[ant:scalac] mycode.scala:25: warning: could not emit switch for @switch annotated match
[ant:scalac] val newId = (oldId: @switch) match {
[ant:scalac] ^
[ant:scalac] one warning found
但是,如果我改为使用以下代码
val oldId :Int = 123;
val i = 1
val newId = (oldId: @switch) match {
case 1 => 1234
case 2 => 5678
case 3 => 1122
case 4 => 3344
}
那么编译器不会给我警告。为什么不能使用Long 并获得tableswitch?
【问题讨论】:
-
自然的问题是为什么编译器不报告原因。该文档确实警告说没有针对两种情况发出警告。