If you load the same class file through two class loaders, Java considers them to be different classes in memory. This might be the problem.
Java has a family of ClassLoaders that load the .class files from disk or jars or remote servers or wherever they are. There are a special loaders for starting up an application but by the time a simple application starts running your code it has put a class loader in place for you and all of your classes will be loaded by the same class loader. Your casting problem shouldn't come up.
But in more complex systems, especially in frameworks like the servlet or EJB containers, there may be more class loaders floating around. The whole setup is framework-specific ... one environment might be very different from another. In EJB land I once had to get the classloader that loaded "this" class in order to load another because of differences in the classpaths.
Here's a Classloader Paper from IBM ... I think it's one that I read a while ago and thought was pretty good. See if it helps.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Mar 07, 2006
Thanks for the info. The error has gone after I restarted the App Server as suggested in the link.