I doubt it's a problem, but if you're worried about the class reference you can
introduce a middle man that will handle the serialization as a string:
class ClassHolder implements Serializable {
private Class<?> clazz;
// constructor, setter, and getter omitted...
private void readObject(ObjectInputStream ois) {
clazz = Class.forName(ois.readUTF());
}
private void writeObject(ObjectOutputStream oos) {
oos.writeUTF(clazz.getName());
}
}
Craig
_____
From: Anthony DePalma [mailto:[email protected]]
To: [email protected]
Sent: Mon, 28 Dec 2009 15:41:00 -0500
Subject: Quick question - Bad to serialize a class reference?
I am making a modal window link component that will fallback to a
standard redirect if javascript is disabled. Traditionally I have been
overriding a method called onFallback() and forcing users to manually
setRedirect(true), setResponsePage(blah), but I would prefer it if I
could just pass the class reference in the constructor and handle that
logic myself in the onclick.
That means serializing the class reference across to the onclick. Are
there performance implications at all? My gut reaction is no because I
see a lot of transient objects in the Class object, but I wanted to
confirm.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]