line 1: you are using "new", so the "ss" will not point to some constant literal in pool line 2: here the value taken as int, and then boxed, i2 will point to constant literal in pool aa: here you are comparing object explicitly created with new, and object created by autoboxing, with value within (-128,127), which is cached in constant pool bb: here ss is unboxed before comparison, so you are comparing just two ints
Hint: next time, try to post your question in English :-) 提示: 下次, 尝试张贴您的问题用英语:-) [ May 27, 2007: Message edited by: John Stone ]
I hope Babelfish translated your question correctly...
Originally posted by SmileFish Fish: System.out.println(i2==startingI);//aa
You are comparing two different Integer objects. One (startingI) constructed as new Integer(25) the other boxed from an integer primitive (the primitive returned from Integer.intValue()), as in i2 = i2.intValue();
Originally posted by SmileFish Fish: System.out.println(s==ss);//bb
You are comparing two integer primitives here.
Now, for an interesting variation try the following: change Integer i=new Integer(25) for Integer i=25; Do you understand the result?
[ May 27, 2007: Message edited by: Sergio Tridente ] [ May 27, 2007: Message edited by: Sergio Tridente ]
On your way in you may have missed that we have a JavaRanch Naming Policy for displayed (screen) names. Your displayed name must consist of a first name (or an initial), a space, and a family name (in that order) and not be obviously fictitious. Since yours "SmileFish Fish", does not conform with it, please take a moment to change it, which you can do right here.
Posters with nonconforming displayed names will be locked out of JavaRanch after a few posts using those names.