Wednesday, 2 October 2013

Inheritance in java, casting subclass to superclass

Inheritance in java, casting subclass to superclass

I am writing a software in java and this inheritance problem always crops
up. Funny enough, I don't get problems when i run the program in my IDE
(Eclipse Kepler) but once i export it to an executable jar, problem
starts. I think am the only one experiencing this problem because all
searches on google show the direct opposite. My problem is I have an
interface named VoteType. This interface is implemented by serveral
concrete classes. I save the concrete implementation to a file using
XMLEncoder and retrieve it using XMLDecoder. But when i try to cast it to
the interface it implements (VoteType), i get a ClassCastException. What
could possibly be causing this? Please help.

No comments:

Post a Comment