反射获得属性和方法

反射获得属性和方法

属性

获取public属性的方法 clazz.getFields()

获取全部属性的方法clazz.getDeclaredFields()

获得指定属性的值 clazz.getDeclaredField("name")

方法

获得所有本类及其父类的所有public方法 clazz.getMethods()

获得指定的本类及其父类的public一个方法 clazz.getMethod("方法名", 参数类名.class)

获得本类的所有方法clazz.getgetDeclaredFieldsMethods()

指定的同上

构造器

获得所有public构造器 clazz.getConstructors()

获得所有构造器 clazz.getDeclaredConstructors()

获得指定构造器clazz.getDeclaredConstructors(参数类的class对象) 如 (int.class)

posted @ 2023-03-13 22:17  Geek李  阅读(23)  评论(0)    收藏  举报