wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrapper class doubt. Can we assign a short variable to Short? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Wrapper class doubt. Can we assign a short variable to Short?" Watch "Wrapper class doubt. Can we assign a short variable to Short?" New topic
Author

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

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Hi,
I have a doubt on the below line as (short ) is being used can we assign short value to Short Wrapper Class.


http://www.lifesbizzare.blogspot.com || OCJP:81%
Carles Gasques
Ranch Hand

Joined: Apr 19, 2013
Posts: 199
    
    1
Since 1.5 jdk release the answer is yes.
James X Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 158
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
 
subject: Wrapper class doubt. Can we assign a short variable to Short?
 
Similar Threads
Doubt
Casting Doubt
A doubt
Reg : doubt
Assignment doubt