Serializing a class
Hi experts, I have a question regarding serializing a java class (not object). I know Class implements the Serializable interface. I encountered a problem when deserializing a Class. The error basically says "failed to build body from bytes. Reason: java.io.IOException: some class name". What's the possible problem? Of cause, when deserializing, the class definition was not preloaded on the classpath... that's why I need to serialize the Class definition and send it a remote server.
Yes but because Class is a generic class that points to the real class, it needs to have a copy of the real class that it represents to be able to be rebuilt.
If the remote server needs a copy of the real class, then what's the point of serializing a class? Is there a way to go around this? I need to serializing code that doesn't exist on a remote machine. Thanks!!
Originally Posted by ra4king
Serialization is used to preserve the instance variable values. If you want to send a .class file to another location, you are going to have to looking ClassLoader and other classes to be able to load this class into the runtime.