Original Post
Hey guys. Recently, I came up with the following dilemma: My game deals with several subclasses of a Monster class, such as Spider and Goblin. Everything is fine until I need to typecast an Object read from an ObjectInputStream to its original subclass, rather than typecasting it to the general Monster class.
My question: Is there a better way to get the monster''s subclass than actually reading a serialized Class object before the monster? In other words, is there a better way than this:
Class monsterClass = (Class)in.readObject();
monsterClass myMonster = (monsterClass)in.readObject();
I don''t really want to serialize a Class object for each monster (or even groups of monsters) in my files if I don''t have to. Is there an alternative?
Thanks in advance,
Ghardoan