• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 35
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:


 
Honk if you love justice! And honk twice for tiny ads!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic