本文共 1186 字,大约阅读时间需要 3 分钟。
import java.util.List;import java.util.ArrayList;import java.lang.reflect.Method;import java.lang.reflect.Field;class S { private String name; private int age; public void setName(String name) { this.name = name; } public String getName() { return this.name; }}public class RefTest { public static void main(String[] args) { try { Class cls = Class.forName("S"); boolean b1 = cls.isInstance(new Integer(37)); System.out.println(b1); boolean b2 = cls.isInstance(new S()); System.out.println(b2); } catch (Throwable e) { System.err.println(e); } try { Class cls = Class.forName("S"); getProperty(cls); } catch (Throwable e) { System.err.println(e); } try { Class cls = Class.forName("S"); getMethods(cls); } catch (Throwable e) { System.err.println(e); } } public static Field[] getProperty(Class ownerClass) throws Exception { Field[] fields = ownerClass.getDeclaredFields(); for (int i=0; i
转载地址:http://fahca.baihongyu.com/