public static final variable in an imported java class

后端 未结 5 1175
故里飘歌
故里飘歌 2021-01-01 16:20

I happen to come across a Java code at my work place. Here\'s the scenario: There are 2 classes - ClassA and ClassB.

ClassA ha

5条回答
  •  走了就别回头了
    2021-01-01 16:50

    It's a binary compatibility issue. References to constant fields are resolved at compile time. The behaviour you are seeing is correct; if you change the values in class A then you will have to re-compile the client (class B). To avoid such problems consider adding constants using an enum type, introduced in Java release 5.0.

提交回复
热议问题