You will have to recompile all classes that reference String constants.
Note that the static final field of a primitive or String type that is initialized with a compile-time constant value (the so-called constant variable ) will be embedded when they are used in other classes.
In other words, if you have these classes:
public class Constants { public static final int FOO = 42; } public class Bar { public void frobnicate() { System.out.println(Constants.FOO); } }
Then at compile time , the FOO value will be compiled into the .class Bar file, which means that Bar no longer refers to Constants at run time!
It also means that any change to FOO will not affect Bar until you recompile Bar with the new Constants.class .
This effect is discussed in detail in JLS ยง13.4.9 final Fields and Constants .
One way to avoid this problem in the future is to make sure that your "constants" are not interpreted by the compiler as constant variables. One way to do this is to move the value assignment from the initializer to a simple assignment through the static initializer block:
public class Constants { public static final int FOO; static { FOO = 42; } }
source share