Java singleton innere Klasse

Ich kenne das Konzept von singleton in Java.
Ich habe Probleme mit dem erstellen von singleton als innere Klasse in Java. Problem tritt auf durch den Inhaber

public class NormalClass {
    private class Singleton {
        private static Singleton instance = null;

        private Singleton() {
        }

        private static class SingletonHolder {
            private static Singleton sessionData = new Singleton();
        }

        public static Singleton getInstance() {
            return NormalClass.Singleton.SingletonHolder.sessionData;
        }
    }

    public void method1() {
        Singleton.getInstance();
    }
}

Fehler ist an der new Singleton () - Konstruktor aufrufen. Wie richtige Aufruf privaten Konstruktor die Singleton-als innere Klasse?

Hinsichtlich

InformationsquelleAutor zmeda | 2012-01-27

Schreibe einen Kommentar