// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;

public class Test {
    public static void main(String[] args) throws Exception {
        ClassLoader cl1 = new URLClassLoader(new URL[] { (new File("../singleton.jar")).toURI().toURL() });
        Class<?> ss1 = cl1.loadClass("singleton.SimpleSingleton");
        Object o1 = ss1.getMethod("getInstance", new Class[0]).invoke(null, new Object[0]);
		System.out.printf("%s - %d\n", o1.getClass().getName(), System.identityHashCode(o1));
        ClassLoader cl2 = new URLClassLoader(new URL[] { (new File("../singleton.jar")).toURI().toURL() });
        Class<?> ss2 = cl2.loadClass("singleton.SimpleSingleton");
        Object o2 = ss2.getMethod("getInstance", new Class[0]).invoke(null, new Object[0]);
		System.out.printf("%s - %d\n", o2.getClass().getName(), System.identityHashCode(o2));
        ClassLoader cl3 = new URLClassLoader(new URL[] { (new File("../singleton.jar")).toURI().toURL() });
        Class<?> ss3 = cl3.loadClass("singleton.SimpleSingleton");
        Object o3 = ss3.getMethod("getInstance", new Class[0]).invoke(null, new Object[0]);
		System.out.printf("%s - %d\n", o3.getClass().getName(), System.identityHashCode(o3));
    }
}
