This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Different Objects
Meaningfully Equivalent Objects
Different Objects
Same Objects
Please Explain !!! < I think it is flaw in JAVA >
Take care
Cheers!!!
SCJP 6.0 96%
(Connecting the Dots ....)
mohammad shaid
Ranch Hand
Joined: May 05, 2010
Posts: 86
posted
0
Integer i3 = Integer.valueOf(12);
Integer i4 = new Integer("12");
i4 is created using new operator and so when you compare it with other wrappers they are not same(meaning they are different)
with new operator you are constructing a new object so with new opeartor you will be creating new objects which will not be the same even if those 2 objects are constructed to hold same primitive values.. Do trial and error method while coding;; you will get to know..
but i5 and i6 are same as (check K&B for assistance)
i am just a learner ;; i hope you get a better view of this concept from experts;;;
Thanks & Regards,
shaad
Sridhar Gudipalli
Ranch Hand
Joined: Nov 02, 2005
Posts: 120
posted
0
Here is the explanation from K&B book (Chapter#3)
In order to save memory, two instances of the following wrapper objects will always be == when their primitive values are the same:
Boolean
Byte
Character from \u0000 to \u007f (7f is 127 in decimal)
Short and Integer from -128 to 127