aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why a primitive variable can point to wrapper object? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Why a primitive variable can point to wrapper object?" Watch "Why a primitive variable can point to wrapper object?" New topic
Author

Why a primitive variable can point to wrapper object?

Mark Moge
Ranch Hand

Joined: Mar 14, 2009
Posts: 96

Can someone explain me why the primitive variable can point to wrapper object?
for example:


SCJP6 | http://programmerutilities.blogspot.com/
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56218
    
  13

It can't. And in your example, it's not.

Java auto-boxing is extracting the value, 45, and assigning it to the int. There is no reference to the Integer instance.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Mark Moge
Ranch Hand

Joined: Mar 14, 2009
Posts: 96

Autoboxing and wrapper classe was added to Java 1.5. So now I can see how it works Thanks for replay.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Why a primitive variable can point to wrapper object?
 
Similar Threads
Garbage Collection
valueOf() method
unboxing, object reference refer to heap vs "class reference"
regarding Wrapper's unboxing
Primitives vs objects Doubt