Question says everything. Is there any special event occurs? I have a class which needs to implement Serializable interface. I am developing an application using Wicket. I have implemented a Factory class which will provide some links (to remove the redundancy of same code block written over and over):
public class NavigationLinkFactory implements Serializable {
private static final long serialVersionUID = 7836960726965363785L;
private NavigationLinkFactory() {
}
private static class SingletonHolder {
public static final NavigationLinkFactory instance = new NavigationLinkFactory();
}
public static NavigationLinkFactory getFactory() {
return SingletonHolder.instance;
}
private Object readResolve() throws ObjectStreamException {
return SingletonHolder.instance;
}
public Link<Serializable> getUserHomeLink() {
return new Link<Serializable>("home", new Model<Serializable>()) {
private static final long serialVersionUID = -8282608926361995521L;
@Override
public void onClick() {
EMSSession session = (EMSSession) getSession();
session.setActiveHorizonalMenu(1);
setResponsePage(HomePage.class);
}
};
}
public Link<Serializable> getProfileLink() {
return getProfileViewLink();
}
public Link<Serializable> getProfileViewLink() {
return new Link<Serializable>("profileView", new Model<Serializable>()) {
private static final long serialVersionUID = 232185489384306999L;
@Override
public void onClick() {
EMSSession session = (EMSSession) getSession();
session.setActiveHorizonalMenu(2);
setResponsePage(ProfileViewPage.class);
}
};
}
}
If I doesn't implement Serializable then I am getting exception at java.io.ObjectOutputStream.writeObject
, which is thrown by the runtime environment of the wicket framework. If I implement it then it is gone.
So what really happens when one calls ObjectInputStream#readobject()
method for some object created by Singleton pattern?
I am not adding wicket tag because I don't think this question is related to the Wicket.