aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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:


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unboxing, object reference refer to heap vs "class reference"
 
Similar Threads
SCJP problem with boxing
Boxing,autoboxing,unboxing
Autoboxing help
Autoboxing vs Unboxing
K & B, SCJP 5 - Errata: Updated 7/28/06