Singleton Lazy Loading Pattern
问题 I am trying to write a Singleton Lazy Loading Pattern. Here is the class: public class IMDBLookup { private static class LazyLoad { private static final IMDBLookup IMDB_LOOKUP; static { IMDB_LOOKUP = new IMDBLookup(); } } public static IMDBLookup getInstance() { return IMDBLookup.LazyLoad.IMDB_LOOKUP; } } I am wondering whether or not I am doing it in a right way? Thanks in advance. 回答1: I prefer to use enum for simplicity. public enum IMDBLookup { INSTANCE; // add fields and methods here. }