public final class Classes extends Object
| Modifier and Type | Method and Description |
|---|---|
static Class<?>[] |
getAllInterfaces(Class<?> cls)
Returns all interfaces implemented by the class or interface represented by
the specified class.
|
static Method |
getDeclaredMethod(Class<?> cls,
String name,
Class<?>... parameterTypes)
Returns a Method object that reflects the specified declared method of the
class or interface represented by
cls (excluding inherited
methods), or null if the method is not found. |
static Method |
getDeclaredMethodDeep(Class<?> cls,
String name,
Class<?>... parameterTypes)
Returns a Method object that reflects the specified declared method of the
class or interface represented by
cls (including inherited
methods), or null if the method is not found. |
public static Class<?>[] getAllInterfaces(Class<?> cls)
Class.getInterfaces() by returning all interfaces (full
depth and breadth) instead of just the interfaces directly
implemented by the class.cls - The class.NullPointerException - If cls is null.public static Method getDeclaredMethod(Class<?> cls, String name, Class<?>... parameterTypes)
cls (excluding inherited
methods), or null if the method is not found.
Declared methods include public, protected, default (package) access, and private visibility.
The name parameter is a String that specifies the simple name of
the desired method, and the parameterTypes parameter is an array of
Class objects that identify the method's formal parameter types, in
declared order. If more than one method with the same parameter types is
declared in a class, and one of these methods has a return type that is
more specific than any of the others, that method is returned; otherwise
one of the methods is chosen arbitrarily. If the name is "<init>"
or "<clinit>" this method returns null. If this Class
object represents an array type, then this method does not find the clone()
method.
This method differentiates itself from
Class.getDeclaredMethod(String,Class...) by returning null
when a method is not found, instead of throwing
NoSuchMethodException.
cls - The class in which to find the declared method.name - The simple name of the method.parameterTypes - The parameter array.cls (excluding inherited
methods), or null if the method is not found.NullPointerException - If cls or name is null.public static Method getDeclaredMethodDeep(Class<?> cls, String name, Class<?>... parameterTypes)
cls (including inherited
methods), or null if the method is not found.
Declared methods include public, protected, default (package) access, and private visibility.
The name parameter is a String that specifies the simple name of
the desired method, and the parameterTypes parameter is an array of
Class objects that identify the method's formal parameter types, in
declared order. If more than one method with the same parameter types is
declared in a class, and one of these methods has a return type that is
more specific than any of the others, that method is returned; otherwise
one of the methods is chosen arbitrarily. If the name is "<init>"
or "<clinit>" this method returns null. If this Class
object represents an array type, then this method does not find the clone()
method.
This method differentiates itself from
Class.getDeclaredMethod(String,Class...) by returning null
when a method is not found, instead of throwing
NoSuchMethodException.
cls - The class in which to find the declared method.name - The simple name of the method.parameterTypes - The parameter array.cls (including inherited
methods), or null if the method is not found.NullPointerException - If cls or name is null.Copyright © 2020. All rights reserved.