Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ClassCastException in Custom class loader

824461Sep 19 2012 — edited Sep 25 2012
I have created a custom class loder.

ClassLoaderDemo ccl = new ClassLoaderDemo(); //assume it is working fine
Class clas = ccl.loadClass( "com.MyObject" );

com.MyObjectSuperClass o1 = (com.MyObjectSuperClass)clas.newInstance();

Now I want to cast the loaded object to MyObjectSuperClass which is super class if MyObject. But I am getting the following exception

Exception in thread "main" java.lang.ClassCastException: com.MyObject cannot be cast to com.MyObjectSuperClass

Please help.
This post has been answered by jtahlborn on Sep 25 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 23 2012
Added on Sep 19 2012
30 comments
1,791 views