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

Wrapper class doubt. Can we assign a short variable to Short?

 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a doubt on the below line as (short ) is being used can we assign short value to Short Wrapper Class.
 
Carles Gasques
Ranch Hand
Posts: 199
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since 1.5 jdk release the answer is yes.
 
James X Peterson
Whizlabs Java Support
Ranch Hand
Posts: 158
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vishal Hegde,

As Carles Gasques said the answer is yes. When Java automatically converts a primitive type like int into corresponding wrapper class object e.g. Integer then its called autoboxing. All primitive types e.g. byte, short, char, int, long, float, double and boolean has corresponding wrapper class e.g. Byte, Short, Integer, Character etc and participate in autoboxing.Since whole process happens automatically without writing any code for conversion its called autoboxing.Compiler uses valueOf() method to convert primitive to Object and uses intValue(), doubleValue() etc to get primitive value from Object.




Regards,
James
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic