Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrapper

 
Thirumalai Muthu
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer i1=100;
Integer i2=new Integer(100);

What is the difference between these two Statements?
Can anyone Please Explain.Thanks
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The second statement explicitly creates a new wrapper instance. But the first statement uses boxing, which either implicitly creates a new wrapper instance, or (because the value is within the range of a byte) references an existing instance. See JLS 5.1.7 for details.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic