| Author |
Regarding type casting
|
Vijay Chandran
Ranch Hand
Joined: Jan 07, 2007
Posts: 175
|
|
Dear friends, Please help me in this type casting problem: I am using JDK 1.4. I want to convert a long(primitive data type) type cast it and assign it to a Long(Wrapper class) variable. Kindly provide your help regarding this pronlem. Thanks in advance. Regards, Vijay
|
 |
Freddy Wong
Ranch Hand
Joined: Sep 11, 2006
Posts: 959
|
|
|
Use Long.valueOf(long)
|
SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
|
 |
Vijay Chandran
Ranch Hand
Joined: Jan 07, 2007
Posts: 175
|
|
Thanks a lot Freddy
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
Note that this is not type-casting. You are constructing a new object. Type casting is for object references or primitives. For object references, you type cast when you have declared a reference as a superclass, but you know that the object it points to is actually of some subclass. For primitives, you type cast when you want to force the primitive value into a variable whose type is not automatically compatible. For instance, you can assign an int value to a long, with no cast. But if you want to assign a long to an int, you need to cast. If the long does not fit in the int, information will be lost.
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
 |
|
|
subject: Regarding type casting
|
|
|