开关语句中的最终变量情况
2022-09-02 12:47:26
final int a = 1;
final int b;
b = 2;
final int x = 0;
switch (x) {
case a:break; // ok
case b:break; // compiler error: Constant expression required
}
/* COMPILER RESULT:
constant expression required
case b:break;
^
1 error
*/
为什么我会收到这种错误?如果我愿意,一切都管用。final int b = 2