getDeclaredMethods和getMethods的区别

[getDeclaredMethods](http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Class.html#getDeclaredMethods)
Returns an array of Method
objects reflecting all the methods declared by the class or interface represented by this Class object.
[getMethods]
(http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Class.html#getMethods)
Returns an array containing Method
objects reflecting all the public member methods of the class or interface represented by this Class
object, including those declared by the class or interface and those inherited from superclasses and superinterfaces.


getDeclaredMethod()获取的是类自身声明的所有方法,包含publicprotectedprivate方法。
getMethod()获取的是类的所有共有方法,这就包括自身的所有public方法,和从基类继承的、从接口实现的所有public方法。

也就说调用getMethods方法输出的是自身的public方法和父类Object的public方法。调用getDeclaredMethods方法输出的是自身的public、protected、private方法。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容