• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with Wrappers?  RSS feed

 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider Comments for Problem .

Integer i= new Integer("45");
int j;

j=i; // This is compiling fine, But y ??

System.out.println(j); // Printing value 45, Again a Magic, Y ?

Thanks

Please do explain also !!!
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sahil:

Please use real words and use code tags. Thanks!

John.
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sahil Rally wrote:j=i; // This is compiling fine, But y ??

Because of auto-unboxing, as is explained on the page Henry linked to.

System.out.println(j); // Printing value 45, Again a Magic, Y ?

System.out is a PrintStream, and its println method is overloaded to take all primitive types. Therein, it will convert the primitive into a String using String.valueOf, and that String is then printed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!