• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrappers

 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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??
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
kshitij dogra
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is actually happening is that the Integer i , is being unboxed and then incremented , and then again boxed back to the value.......
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic