hashcode()请教
要求是:
自己继承Classloader。。实现一个Myclassloader。
然后创建两个loader对象,分别加载同一个类。
然后再分别通过loader对象创建两个实例。然后把所有涉及的对象的hashcode都输出出来。
我的代码如下:
MyClassLoader ml = new MyClassLoader(); MyClassLoader ml2 = new MyClassLoader(); Class c1 = ml.loadClass("TestClass"); Class c2 = ml2.loadClass("TestClass"); TestClass tc1 = (TestClass) c1.newInstance(); TestClass tc2 = (TestClass) c2.newInstance(); System.out.println("TestClass[" + c1.hashCode() + "] loaded by MyClassLoader[" + ml.hashCode() + "]"); System.out.println("TestClass[" + c2.hashCode() + "] loaded by MyClassLoader[" + ml2.hashCode() + "]"); System.out.println("Object 1 [" + tc1.hashCode() + "] is instance of TestClass[" + c1.hashCode() + "]"); System.out.println("Object 2 [" + tc2.hashCode() + "] is instance of TestClass[" + c2.hashCode() + "]"); System.out.println(tc1.equals(tc2));