Recently,I want change some arguments of JVM so that I can change the cache for Integer value , but some problems have appeared:
Sourse code:
public class test {
public static void main(String[] args) {
Integer i1=300;
Integer i2=300;
System.out.println(i1==i2);
}
}
If I use "java test" to run this procejure , and normally it will print "false".
Details:
1:javac test.java
2:jvva -server test.java
3:java -Djava.lang.Integer.IntegerCache.high=200 test
4:java -server -Djava.lang.Integer.IntegerCache.high=200 test
5:java -XX:AutoBoxCacheMax=200 test
6:java -server -XX:AutoBoxCacheMax=200 test
7:java -server -XX:+AggressiveOpts test
And when I changed all the arguments and it should print "false" , but to my surprise it should be "true" . And I know
if i1 is 100 and i2 is 100 , then I use "java test" to run this procejure getting the result of "true" cuz they are
between -128~127 . And if i1 is 200 and i2 is 200 , then the result will be "false" cuz they are beyond the rainge of
-128~127 , however when I change the final varible high to 200 , the result will be "true" . So all the conclusion
above you think right , ok ? But now , I have made a change again , i1 is 300 and i2 is 300 , and I just keep the value
of final varible high(200) , and why it should be "true" at last ? Cuz i1 and i2 are beyond the rainge of -128~200 , so
what is the problem with it ?