public class Company { private static Company instance = new Company(); private Company() { } public static synchronized Company getInstance() { return instance; } }
//被前面人抢先了... public class Company { private static Company c = null; private Company() { } public static synchronized Company getInstance() { if(c == null)c = new Company(); return c; } }
public class Company { private static Company c = null; private Company() { } public static synchronized Company getInstance() { if(c == null)c = new Company(); return c; } }