Tuesday, September 6, 2011

Public Final Static Variable remains old value

Recently I deployed a class file to production and this class file contains only Public Final Static Variables (I am not sure why they design it this way but I think the purpose is for easy to change in future) to be call by other classes. Then I notice the changes no taken place, no matter what I do. I delete the catch in Tomcat and Broswer but still the same. Until I do a full recompile and deploy to production it take the changes in place.

For example, you have 2 files called MainClass.java and StaticVariable.java. The MainClass.java file is calling the variable in StaticVariable.java file to get the value from the static variable. If you make some changes on the value in StaticVariable.java file without compiling MainClass.java, it will always remain the old value in MainClass.java. You have to recompile MainClass.java for the changes to take effect.

public class MainClass {

public static void main(String args[]) {

System.out.println(StaticVariable.HELLO);

}

}

public class StaticVariable {

public final static String HELLO = "HELLO";

//public final static String HELLO = "hello";

}

In order to get the new value in the variable, you have to recompile all the java files that calling the StaticVariable.java. That is a compile time constant.

1 comment:

Anonymous said...

youtube:how to play video poker and live in casino
play video poker and live in casino. Video poker and live in casino. We explain how video poker works and make money using casino youtube convert to mp3 software.