File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Class casting a null pointer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Class casting a null pointer" Watch "Class casting a null pointer" New topic
Author

Class casting a null pointer

Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
    
    1
Is it always safe to cast a null pointer to a certain Class?
I have the habit of doing this
Object o = vector.get(1);
String str = o == null ? null : (String)o;
I wonder if I can leave out the checking altogether to save processing time.
Chu
[ May 08, 2002: Message edited by: Chu Tan ]
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
Yes it's safe.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class casting a null pointer