Class(java.lang.Class)类中成员函数的区别

来源:互联网 发布:唱歌学英语软件 编辑:程序博客网 时间:2024/05/22 00:41

一、 getFields()与getDeclaredFields()区别:

(1)getFields()只能访问类中声明为公有的字段,私有的字段它无法访问.

(2)getDeclaredFields()能访问类中所有的字段,与public,private,protect无关   

二、 getMethods()与getDeclaredMethods()区别:

(1) getMethods()只能访问类中声明为公有的方法,私有的方法它无法访问,能访问从其它类继承来的公有方法.

(2)getDeclaredFields()能访问类中所有的字段,与public,private,protect无关,不能访问从其它类继承来的方法   

三、getConstructors()与getDeclaredConstructors()区别:

(1)getConstructors()只能访问类中声明为public的构造函数.

(2)getDeclaredConstructors()能访问类中所有的构造函数,与public,private,protect无关

原创粉丝点击