美文网首页
getDeclaredMethods和getMethods的区别

getDeclaredMethods和getMethods的区别

作者: 蝌蚪1573 | 来源:发表于2016-10-12 11:10 被阅读0次

[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方法。

相关文章

  • Java 反射知识点

    反射类概念 获取类Class 获取类 getMethods 和 getDeclaredMethods 区别 Cla...

  • getDeclaredMethods和getMethods的区别

    [getDeclaredMethods](http://download.oracle.com/javase/1....

  • Java反射常用API

    getMethods() getMethods()获取本类以及父类中所有public修饰符修饰的方法,包括本类和父...

  • java SE

    public staticMethod[]getDeclaredMethods(Classclazz) { Set...

  • 反射中getDeclaredMethods()和getMetho

    在API中关于这两个方法是这么解释的1:getMethods(),该方法是获取本类以及父类或者父接口中所有的公共方...

  • 关于java反射

    //getDeclaredMethods 返回当前类定义的所有方法 (Field同理) //getMethod...

  • Java反射调用

    getDeclaredMethods() :反映此 Class 对象表示的类或接口声明的所有方法,但不包括继承的方...

  • &和&&,| 和 || 的区别

    &不管前面的条件是否正确,后面都执行 &&前面条件正确时,才执行后面,不正确时,就不执行,就效率而言,这个更好。 ...

  • &和&&, |和||的区别

    &和&&的含义一样, 表示逻辑与(and), 只有第一个表达式和第二个表达式都为 true 时, 整个运算结果才为...

  • &&和&,|和||的区别

    1 &&和&的区别 1 单&时,无论左边真假,右边都会进行计算 2 双&&时,只有左边为真时,右边才会进行计算,左...

网友评论

      本文标题:getDeclaredMethods和getMethods的区别

      本文链接:https://www.haomeiwen.com/subject/eghiyttx.html