Java Reflection: Difference between getMethods() and getDeclaredMethods()
JavaJava Problem Overview
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
Java Solutions
Solution 1 - Java
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
.