java为什么在给出错误的开关中使用整数引用作为case常量?
public class Switch {
public static void main(String[] args) {
final Integer i=new Integer(2);
switch(i)
{
case i:System.out.println("hi");
}
}
}
当我编译它的时候,它给出了一个错误,说这个案例必须是一个consant,但如果我写下面的代码,那么就没有错误。为什么会这样
public class Switch {
public static void main(String[] args) {
final int i=2;
switch(i)
{
case i:System.out.println("hi");
}
}
}
共 (0) 个答案