Java static final values replaced in code when compiling?

后端 未结 10 1302
死守一世寂寞
死守一世寂寞 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:07

    As an optimization the compiler will inline that final variable.

    So at compile time it will look like.

    class b
    {
          Object[] temp = new Object[100];
    }
    

提交回复
热议问题