Java Reflection: Difference between getMethods() and getDeclaredMethods()

后端 未结 1 1870
温柔的废话
温柔的废话 2021-02-05 00:15

Can someone please elaborate on this, and explain the difference between the two methods, and when/why you would want to use one over the others

1条回答
  •  醉梦人生
    2021-02-05 00:44

    getDeclaredMethods includes all methods declared by the class itself, whereas getMethods returns only public methods, but also those inherited from a base class (here from java.lang.Object).

    Read more about it in the Javadocs for getDeclaredMethod and getMethods.

    0 讨论(0)
提交回复
热议问题