compilation issues with static final fields when using Ant.

Consider this code:

class A{
public static final String myStaticString=”hello world”;
}

class B {
public static void main(String args[]) {
System.out.println(A.myStaticString);
}
}

Such a reference can cause issues if you change value of final static field in A and compile class A and don’t recompile classB. In such a case, classB will keep printing the old value. This is because of the compiler optimization. The java compiler replaces the references to¬† ‘A.myStaticString’ with the actual string “hello world” when you compile it the first time. This is a common issue with build tools like Ant.