This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrappers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Wrappers" Watch "Wrappers" New topic
Author

Wrappers

James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580



Both t and I are reference variables, holding the memory location of their respective objects.
Using final(for the test object) ,implies that the contents of the reference cannot be changed BUT the object state can be changed.
Isn't it the same for Integer reference. If not why??


SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Because the increment operation tries to unbox the Integer, increment it, create a new Integer with that value and assign it to I.

Edit: wrapper classes are immutable


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
kshitij dogra
Ranch Hand

Joined: Dec 28, 2008
Posts: 39
What is actually happening is that the Integer i , is being unboxed and then incremented , and then again boxed back to the value.......


SCJP 5.0 - 100%
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

got it..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrappers
 
Similar Threads
final variables can be manipulated ...found this in SCWCD book by Bert!
A question about passed by value
Wrapper objects are immutable???
What is the difference between Integer and int
static final references