English 中文(简体)
究竟是怎样通过单一州模式制造一个可再生物体?
原标题:What happens when a Serializable object is created via Singleton Pattern?

问题就是指一切。 是否发生了任何特别活动? 我有一个班子,需要实施可扩展的接口。 我正在利用Wicket开发申请。 我已实施一个工厂级,提供一些链接(消除所书写的同一代码块的重复):

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);
            }
        };  
    }
}

如果我确实能够实施Serializable,那么,我就在java.io.ObjectOutputStream.writeObject上成为例外,而这一条被威热框架的操作环境所推翻。 如果我执行,那就已经过去了。

因此,当有人打电话<条码>,对单一州模式制造的某些物体采用“客观输入Stream#readobject(”方法时,究竟发生了什么?

我没有加入“威望”标签,因为我不认为这个问题与世俗有关。

最佳回答

不幸的是,因违约而发生的情况是,你第二次(或第三次,或第三十七次)接受你的单一州——不是好事。 Luckily有办法围绕这一点:通过实施readResolve() 方法,这种方法可以退还替代物体——就你而言,是正确的单一吨物体——而不是因违约序列化而退还的物体。 链接描述了这些细节,但很简单——你只是采用这种无足轻重的推算法来归还单一吨物体。

问题回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签