J
Jimi Hullegård
Is there a way to avoid a ClassCastException when there is no real changes
made to the class, but the java-file has been compiled anyway?
I'm writing a J2ee web application, and I store a HashMap of User objects as
an attribute in the servlet context. Now, if the User class gets recompiled
(no changes has been made in the code), I get a ClassCastException when I
try to fetch an User from the HashMap.
Code:
Map<Integer, User> onlineUsers = (Map<Integer,
User>)servletContext.getAttribute("onlineUsers");
User user = onlineUsers.get(new Integer(memberId)); <--- this throws a
ClassCastException
But if I don't do "User user = ..." and just prints the object returned, the
it clearly IS a User object, because printout is something like
community.login.User@861f24
So is there a way to "Cast" an object between two classes that actually are
the SAME class, but different versions (I guess)?
/Jimi
made to the class, but the java-file has been compiled anyway?
I'm writing a J2ee web application, and I store a HashMap of User objects as
an attribute in the servlet context. Now, if the User class gets recompiled
(no changes has been made in the code), I get a ClassCastException when I
try to fetch an User from the HashMap.
Code:
Map<Integer, User> onlineUsers = (Map<Integer,
User>)servletContext.getAttribute("onlineUsers");
User user = onlineUsers.get(new Integer(memberId)); <--- this throws a
ClassCastException
But if I don't do "User user = ..." and just prints the object returned, the
it clearly IS a User object, because printout is something like
community.login.User@861f24
So is there a way to "Cast" an object between two classes that actually are
the SAME class, but different versions (I guess)?
/Jimi