SingletonHungryMan { public void sayHello() { System.out.println("hello"); } private  SingletonHungryMan(); void sayHello(); final static SingletonHungryMan INSTANCE; }
@Test public void testClassLoader() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchFieldException, ClassNotFoundException { SingletonHungryMan sone = SingletonHungryMan.INSTANCE; Object stwo = createAnotherInstanceUsingAnotherClassLoader(); sone.sayHello(); invokeMethod(stwo, "sayHello"); }
@Test public void testReflection() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException, ClassNotFoundException { SingletonHungryMan sone = SingletonHungryMan.INSTANCE; Object stwo = createAnotherInstanceUsingRelection(); sone.sayHello(); invokeMethod(stwo, "sayHello"); }