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

Qn on Wrapper classes.

 
Girish Nagaraj
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the following snippet of code from Marcus green mock exam

Integer ten = new Integer(10);
Long nine = new Long (9);
System.out.println(ten + nine);

int i=1;
System.out.println(i + ten);

Output is 19 followed by 11.
But what anwer says is :

Compile time error

The wrapper classes cannot be used like primitives.

Why the diff. I am using java sdk 1.5.
Will the output be diff. if I use sdk 1.4.
 
Shaliey Gowtham
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only from 1.5 you having unboxing
This code is valid only from 1.5 so in 1.4 its a compiler error
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the -source 1.4 option to see what would happen with java 1.4
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic