Java static final values replaced in code when compiling?

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

    Actually I ran into this bizarreness a while ago.

    This will compile "100" into class b directly. If you just recompile class A, this will not update the value in class B.

    On top of that, the compiler may not notice to recompile class b (at the time I was compiling single directories and class B was in a separate directory and compiling a's directory did not trigger a compile of B)

提交回复
热议问题