Skip to Main Content

New to Java

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!

mypackage.MyClass cannot be cast to mypackage.MyClass

843789Jul 28 2009 — edited Jul 31 2009
I guess, my problem is that I have 2 jar files, both containing the same packages but some different versions of classes.
They do not need each other, it just happens the VM did not unload the first jar file while I'm now using the other version (my guess).

I know that "MyClass" is the same in both jar files, a cast would be possible.

Of course I'd prefer that all references restrict their class search to the same jar file, if possible.
I'd prefer to keep the packages as they are. Finally the latest version only would be sufficient,
and would avoid that "cannot cast"

And I'd prefer not to rename the packages to make them different.

- How can I avoid this ClassCastException ?

- Do I need to explicitly work with the ClassLoader ? And if so, how ?
( I was so happy to solve all ClassNotFound problems, up to now, without explicitly dealing with that mystery ClassLoader)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 28 2009
Added on Jul 28 2009
20 comments
504 views