Recently wrote a project encountered a problem, back and forth a few times, finally explored clearly. No nonsense, on the example.
Background: Because the project is small and the configuration file is not used, all static constants are placed inside the Config.java.
public class Config {public static final String url= "http://www.xxxx.com/"; public static final int page_num=10;}
It looks good too, no big problem, it's all used.
Well, put it on the server and run it, normal.
Next, the question comes.
URL change, Page_num also changed.
public class Config {public static final String url= "http://www.yyyy.com/"; public static final int page_num=200;}
OK, generate the next class file, put it on the server, have a cup of tea ...
Refresh under, unchanged, and so on, the server has a conversion time ...
30s ... Hasn't changed.
1min ... Hasn't changed.
Restart the server ... (It should be OK)
Why still not change [email protected]@@###&&&+++*** (What's going on, the server is broken, re-installed?) )
In fact, nothing is bad. You don't believe me? Look down.
Find a gadget, decompile the class file, and look for a reference constant, and you'll see for a moment.
It's not what you think.
Config.URLConfig.PAGE_NUM
But
"http://www.xxxx.com/" 10
See, constants are replaced with values directly in the class file.
That still want to use Config.java, do not want to change many places, how to do?
Two methods:
public class Config {public static final string Url=new string ("http://www.xxxx.com/");//Useful public static final int page_num=new Integer (10);//Bad use}
public class Config {public static String GetURL () {return ' http://www.yyyy.com '; } public static int Getpagenum () {return; }}
Well, the rest, waiting for everyone to find out.
What is the static constant in the class file?