Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes wrapper doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "wrapper doubt" Watch "wrapper doubt" New topic
Author

wrapper doubt

akash azal
Ranch Hand

Joined: Jan 31, 2009
Posts: 70

Which produces the output:
true
567 568
false

how the last output is coming false

We will keep things moving!!
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

This statement y++; is converted too

y = Integer.valueOf(y.intValue() + 1);

So basically y is assigned a new reference to an Integer object. If you remember, all the wrapper classes are immutable i.e. the value in them cannot be changed...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Deepesh Deomurari
Greenhorn

Joined: Oct 29, 2008
Posts: 17
Another interesting fact is that if you add y-- after y++ to make both values equal then also answer will be false.

Integer wrapper use only 8 bytes while comparing using == operator. Max allowed value of operand to be true is 127)


Deepesh Deomurari<br />"When Going Gets Tough,<br />The Tough, Gets Going."
SCJP 1.5 -94%
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Deepesh you are not right. The reason is the one that I gave. You can test it with this



Still the last output will be false.
Deepesh Deomurari
Greenhorn

Joined: Oct 29, 2008
Posts: 17
Oh! I haven't looked at complete question because I found the clue at very first line My fact is also true. But primary resolution is given by you . Thanks for correction .
 
 
subject: wrapper doubt