File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes instanceof and casts 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 "instanceof and casts" Watch "instanceof and casts" New topic
Author

instanceof and casts

Anna Dow
Greenhorn

Joined: Jun 04, 2002
Posts: 18
Hi, all,
here is my question:
It looks that if returned true, then the cast is always possible.
(That is, the code like:

will never give a ClassCastException.) Is it true ?
Thanks, Anna
Gautam Sewani
Ranch Hand

Joined: Apr 19, 2002
Posts: 93
Yeah thats true.
But the code which you gave wont compile
coz you didn't use the if statement properly

should be made


Regards
Gautam
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: instanceof and casts