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
Suppose ClassA looks like this:
public class ClassA {
public static final int FOO = 1;
public static final int BAR = 2;
}
If you recompile it, ClassB will continue using the old values. I guess it could depend on the compiler, but I think this is the typical behaviour. If you don't want to recompile ClassB everytime a constant in ClassA changes, you'll have to do something like this:
public class ClassA {
public static final int FOO = CONST(1);
public static final int BAR = CONST(2);
public static int CONST(int i) { return i; }
}
Becuase now javac is unwilling to inline the constants. Instead it will call the CONST(int) method when ClassA's static initializer runs.