java中Class类的使用 import java.io.*; import java.lang.reflect.*; class ClassTest { public ClassTest(){ } public static void main(String[] args) throws Exception{ ClassTest test=new ClassTest(); ClassTest test1=test.getClass().newInstance(); test1=test; test.printMessage(); test1.printMessage(); System.out.println(test.hashCode()); System.out.println(test1.hashCode()); Method[] method=test1.getClass().getMethods(); for(Method m :method){ System.out.println(m.getDeclaringClass()); System.out.println(m.getName()); } } public void printMessage(){ System.out.println("Created successful!"); } }