Difference between final variables and compile time constant

后端 未结 5 1539
孤城傲影
孤城傲影 2021-01-31 03:59

What is the difference between final variables and compile time constants?

Consider the following code

final int a = 5;
final int b;
b=6;
int x=0;
switch         


        
5条回答
  •  庸人自扰
    2021-01-31 04:41

    The switch statement needs a constant. As final variables can be delayed initialized and the compiler cannot determine for b that it has a value in the case branch.

提交回复
热议问题