Thursday, October 25, 2007

ClassCastException

When do you get ClassCastExceptionn? When you try to cast an object to Class other than its class or its super class.
However you may get ClassCastException when you try to cast an Object whose class's ClassLoader and the ClassLoader of the Class to whom you are trying to cast are neither same nor later ClassLoader an ancestor (parent or grant parent etc) of former ClassLoader.
See the attached code demonstrating the same.
http://rejeev.googlepages.com/source_code_ClassCastExceptionExampl.zip

No comments: