File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding type casting

 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 959
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use Long.valueOf(long)
 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Freddy
 
Peter Chase
Ranch Hand
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic