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[]) {

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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: