Returns an array containing Method
objects reflecting all the
public 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.
If this Class
object represents an array type, then the
returned array has a Method
object for each of the public
methods inherited by the array type from Object
. It does not
contain a Method
object for clone()
.
If this Class
object represents an interface then the
returned array does not contain any implicitly declared methods from
Object
. Therefore, if no methods are explicitly declared in
this interface or any of its superinterfaces then the returned array
has length 0. (Note that a Class
object which represents a class
always has public methods, inherited from Object
.)
The returned array never contains methods with names " <init>
"
or " <clinit>
".
The elements in the returned array are not sorted and are not in any particular order.
Generally, the result is computed as with the following 4 step algorithm.
Let C be the class or interface represented by this Class
object:
getDeclaredMethods()
and filtered to include only public
methods. Object
, then include the result
of invoking this algorithm recursively on the superclass of C. Method
objects representing the
public methods of this class
SecurityException
| If a security manager, s, is present and
the caller's class loader is not the same as or an
ancestor of the class loader for the current class and
invocation of s.checkPackageAccess() denies access to the package
of this class. |
@apiNote There may be more than one method with a particular name
and parameter types in a class because while the Java language forbids a
class to declare multiple methods with the same signature but different
return types, the Java virtual machine does not. This
increased flexibility in the virtual machine can be used to
implement various language features. For example, covariant
returns can be implemented with bridge methods; the bridge
method and the overriding method would have the same
signature but different return types.
@jls 8.2 Class Members
@jls 8.4 Method Declarations
Diagram: Class, Package, Module