mypackage.MyClass cannot be cast to mypackage.MyClass
843789Jul 28 2009 — edited Jul 31 2009I 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)