Java static final values replaced in code when compiling?

后端 未结 10 1289
死守一世寂寞
死守一世寂寞 2020-11-28 10:27

In java, say I have the following

==fileA.java==
class A
{  
    public static final int SIZE = 100;
}  

Then in another file I use this valu

10条回答
  •  旧巷少年郎
    2020-11-28 11:09

    Java does optimise these sorts of values but only if they are in the same class. In this case the JVM looks in A.SIZE rather than optimizing it because of the usage case you are considering.

提交回复
热议问题