This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class casting a null pointer

 
Justin Chu
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it's safe.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic