Java static final values replaced in code when compiling?

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

    You can keep the constant from being compiled into B, by doing

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

提交回复
热议问题