Correctly casting serialised objects

Started by
11 comments, last by hplus0603 10 years, 7 months ago

You could do, say:

obj.getClass().cast(obj);

Dunno what would accomplish but it can be done (and I find it rather funny :D )

In any case, here is an IBM article about Java serialization, might help http://www.ibm.com/developerworks/library/j-5things1/

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Advertisement

Thanks for all the replies and a great discussion! I ended up implementing a Factory class as smr and Bacterius have suggested and believe it is a suitable solution for now. I am trying to hack up the network layer reasonably quickly so I can begin to implement the more exciting details of the game, but at the same time I want it to be a reasonable solution that follows some common conventions.

This is why I have opted to use the Externalizable interface rather than retain full control over the data.

Also, thank you for your explanation of the Dispatcher Sprangle, I will most likely end up implementing something of this sort when I move onto message handling.

You should never go through pain Object IMO. If you manufacture objects from a factory, make them derive from IFactoryOutput. Make the interface have whatever polymorphic functionality you need, such as "handleIncomingMessage" or whatever.

switch() is a signal that you're doing something wrong.

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement