@Test public void testBeanUtil() { Singleton s1 = Singleton.newInstance; s1.doSomething(); Singleton s2 = Singleton.newInstance; s2.doSomething(); boolean b = s1.equals(s2); System.out.println(b); } /** * singleton object * @author cai hao * @date 2018年2月8日 * */ public enum Singleton { newInstance; private Singleton() { System.out.println("singleton constructor"); } public void doSomething() { System.out.println("Singleton do something ..."); } }