Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Wrapper class doubt  RSS feed

 
Vishal Hegde
Ranch Hand
Posts: 1078
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer i=new Integer(100);
System.out.println(i); // why is this line printing 100 and not the reference address
 
Rob Spoor
Sheriff
Posts: 21088
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the Integer class has its toString() method overridden.

And you never see the reference address of objects. What you see when you print an Object instance is its hashCode. It is most likely based on the object address in memory, but it doesn't have to. It most certainly never is the reference address - that's completely hidden. Remember, references aren't pointers like in C.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!