public final class BetterMethodFinder extends Object
Constructor and Description |
---|
BetterMethodFinder(Class<?> clazz)
Create instance for given class.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
Constructor<?> |
findConstructor(Class<?>[] parameterTypes)
Returns the most specific public constructor in my target class that accepts the number and
type of parameters in the given Class array in a reflective invocation.
|
Method |
findMethod(String methodName,
Class<?>[] parameterTypes)
Returns the most specific public method in my target class that has the given name and accepts
the number and type of parameters in the given Class array in a reflective invocation.
|
static Class<?>[] |
getParameterTypesFrom(Object[] args)
Return an array of Class objects for the objects in the given array.
|
static Class<?>[] |
getParameterTypesFrom(String[] classNames)
Return an array of Class objects named by the FQNs in the given String array.
|
static Class<?>[] |
getParameterTypesFrom(String[] classNames,
ClassLoader loader)
Return an array of Class objects named by the FQNs in the given String array.
|
int |
hashCode() |
public BetterMethodFinder(Class<?> clazz)
clazz
- Class in which I will look for methods and constructorsIllegalArgumentException
- if clazz is null, or represents a primitive, or represents
an array typepublic Constructor<?> findConstructor(Class<?>[] parameterTypes) throws NoSuchMethodException
A null value or Void.TYPE in parameterTypes matches a corresponding Object or array reference in a constructor's formal parameter list, but not a primitive formal parameter.
parameterTypes
- array representing the number and types of parameters to look for in the
constructor's signature. A null array is treated as a zero-length array.NoSuchMethodException
- if no constructors match the criteria, or if the reflective
call is ambiguous based on the parameter typespublic Method findMethod(String methodName, Class<?>[] parameterTypes) throws NoSuchMethodException
A null value or Void.TYPE in parameterTypes will match a corresponding Object or array reference in a method's formal parameter list, but not a primitive formal parameter.
methodName
- name of the method to search forparameterTypes
- array representing the number and types of parameters to look for in the
method's signature. A null array is treated as a zero-length array.NoSuchMethodException
- if no methods match the criteria, or if the reflective call is
ambiguous based on the parameter types, or if methodName is nullpublic static Class<?>[] getParameterTypesFrom(Object[] args)
args
- an Object arraypublic static Class<?>[] getParameterTypesFrom(String[] classNames) throws ClassNotFoundException
classNames
- String array of fully qualified names (FQNs) of classes or primitives.
Represent an array type by using its JVM type descriptor, with dots instead of slashes
(e.g. represent the type int[] with "[I", and Object[][] with "[[Ljava.lang.Object;").ClassNotFoundException
- if any of the FQNs name an unknown classpublic static Class<?>[] getParameterTypesFrom(String[] classNames, ClassLoader loader) throws ClassNotFoundException
classNames
- String array of fully qualified names (FQNs) of classes or primitives.
Represent an array type by using its JVM type descriptor, with dots instead of slashes
(e.g. represent the type int[] with "[I", and Object[][] with "[[Ljava.lang.Object;").loader
- a ClassLoaderClassNotFoundException
- if any of the FQNs name an unknown classCopyright © 2022. All rights reserved.