This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes unboxing, object reference refer to heap vs 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 "unboxing, object reference refer to heap vs "class reference"" Watch "unboxing, object reference refer to heap vs "class reference"" New topic
Author

unboxing, object reference refer to heap vs "class reference"

wei liu
Ranch Hand

Joined: Nov 19, 2008
Posts: 35

Can someone help me to understand this paragraph from SCJP book

SCJP sun certified programmer for java 6 exam 310-065 book page 606 in the exam watch

"Remember that unboxing can't convert a plain old object to a primitive, even if that object reference refers to an integer(or some other wrapped primitive) on the heap.
unboxing converts onoly from a wrapper class reference (like an Integer or Long) to primitive.
"

I am quite confused about the concept between object reference refers to an integer on the heap vs unboxing converts onoly from a wrapper class reference (like an Integer or Long) to primitive., Can someone provide some examples to help me understand the difference between them.


thanks in advance


SCJP 1.6 in 2010
SCWCD5 in 2011
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

Means unboxing only works if you are having an object of some wrapper class like :



Here i is a wrapper class and we can directly assign i to and integer (primitive) variable.

But this will not work if you have an object of Object class which is referring to an object of Wrapper class like:


 
GeeCON Prague 2014
 
subject: unboxing, object reference refer to heap vs "class reference"