This post originated from an RSS feed registered with Java Buzz
by Joe Shelby.
Original Post: instanceof vs. ClassCastException
Feed Title: Joe's Java Jottings
Feed URL: http://www.blog-city.com/bc/
Feed Description: Notes, observations, and occasional other stuff on Java, with concentrations on Swing, XML, and the Semantic (Object) Web.
These guys did some tests on whether or not doing instanceof checks before casting were more or less expensive than waiting for the ClassCastException, and found that basically, the overhead of creating the exception, throwing and catching it, the potential for unstable-states, and all that lot really got in the way. The best practice approach is to go ahead and do the instanceof check first.
However, i would caveot t