|
![]() |
Passed: SCJP 6 (90%), SCJD 6
Other: Spring training, extensive Swing experience
which implies to me that comparing wrappers and primitives, regardless of whether boxing takes place, always works with == and !=.
Am I right or have I misunderstood the objective?
Passed: SCJP 6 (90%), SCJD 6
Other: Spring training, extensive Swing experience
Whizlabs Support (info@whizlabs.com or +91-9971838640 )
OCAJP 8 | OCPJP 8 | OCEJWCD | OCMJEA
Jacob Sonia wrote:Hi, when i read this i understood this:
if we say
Integer i = 127;
Integer j = 127;
if(i == j) //returns true;
Integer i = 129;
Integer j = 129;
if(i == j) // returns false;
but it will not work here because using new always create a new object, so == starts comparing references now
Integer i = new Integer(127);
Integer j = new Integer(127);
if(i == j) //returns false
Correct me if i am wrong
SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
SCJP 1.4 : 91%
SCWCD 1.4 : 95%
SCBCD 1.3 : 95%
SCJP 6 Upgrade : 95%
Next SCBCD 1.5
Man is not finished when he is defeated. He is finished when he quits.
AmitKumar Jain wrote:Hi Bob,
I disagree slightly. Though you are correct, the statement requires correction.
== in case of references, checks whether the references point to the same object.
[ == in no way can compare objects , it just compares the references , which are
nothing but object handles ]
Amit
SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
SCJP 1.4 : 91%
SCWCD 1.4 : 95%
SCBCD 1.3 : 95%
SCJP 6 Upgrade : 95%
Next SCBCD 1.5
Man is not finished when he is defeated. He is finished when he quits.
SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|