更新时间:2022-04-04 22:39:21
编译时间常数必须为:
所以私人决赛int x = getX();
不是常数。
到secon d问题 private int y = 10;
不是常量(在这种情况下是非final),因此优化器无法确定该值将来是否会发生变化。所以它不能像恒定值那样优化它。答案是:不,它的处理方式与编译时间常数不同。
To the second question private int y = 10;
is not constant (non-final in this case), so optimizer cannot be sure that the value would not change in the future. So it cannot optimize it as good as constant value. The answer is: No, it is not treated the same way as compile time constant.