public class ReflectUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
METHOD_GET_PREFIX
The Constant METHOD_GET_PREFIX.
|
static String |
METHOD_IS_PREFIX
The Constant METHOD_IS_PREFIX.
|
static String |
METHOD_SET_PREFIX
The Constant METHOD_SET_PREFIX.
|
static Object[] |
NO_ARGUMENTS
an empty object array.
|
static Class[] |
NO_PARAMETERS
an empty class array.
|
static Type[] |
NO_TYPES
an empty object array.
|
| Constructor and Description |
|---|
ReflectUtil() |
| Modifier and Type | Method and Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|
static boolean |
compareDeclarations(Method first,
Method second)
Compares method declarations: signature and return types.
|
||||||||
static boolean |
compareParameters(Class[] first,
Class[] second)
Compares method or ctor parameters.
|
||||||||
static boolean |
compareSignatures(Constructor first,
Constructor second)
Compares constructor signatures: names and parameters.
|
||||||||
static boolean |
compareSignatures(Field first,
Field second)
Compare signatures.
|
||||||||
static boolean |
compareSignatures(Method first,
Method second)
Compares method signatures: names and parameters.
|
||||||||
static <T,V> V |
executeMethod(T type,
String methodName,
boolean equalsIgnoreCase,
Object... args)
Finds the method based on the name provided and executes the method by
passing the arguments.
|
||||||||
static <T,V> V |
executeMethod(T type,
String methodName,
boolean equalsIgnoreCase,
String... args)
Finds the method based on the name provided and executes the method by
passing the arguments.
|
||||||||
static Method |
findDeclaredMethod(Class c,
String methodName)
Find declared method.
|
||||||||
static Method |
findMethod(Class c,
String methodName)
Returns method from an object, matched by name.
|
||||||||
static void |
forceAccess(AccessibleObject accObject)
Suppress access check against a reflection object.
|
||||||||
static Field[] |
getAccessibleFields(Class clazz)
Gets the accessible fields.
|
||||||||
static Field[] |
getAccessibleFields(Class clazz,
Class limit)
Gets the accessible fields.
|
||||||||
static Method[] |
getAccessibleMethods(Class clazz)
Returns array of all methods that are accessible from given class.
|
||||||||
static Method[] |
getAccessibleMethods(Class clazz,
Class limit)
Returns array of all methods that are accessible from given class, upto
limit (usually
Object.class). |
||||||||
static String |
getBeanPropertyGetterName(Method method)
Returns beans property getter name or
null if method is not
a real getter. |
||||||||
static String |
getBeanPropertySetterName(Method method)
Returns beans property setter name or
null if method is not
a real setter. |
||||||||
static Class[] |
getClasses(Object... objects)
Returns classes from array of specified objects.
|
||||||||
static Class |
getComponentType(Type type)
Returns component type of the given
type. |
||||||||
static Class |
getComponentType(Type type,
int index)
Returns the component type of the given
type.For example the following types all have the component-type MyClass: MyClass[] List<MyClass> Foo<? extends MyClass> Bar<? super MyClass> <T extends MyClass> T[] |
||||||||
static <T> Field |
getDeclaredField(T type,
String name,
boolean equalsIgnoreCase)
Gets the declared field.
|
||||||||
static <T> Method |
getDeclaredMethod(T type,
String methodName,
boolean equalsIgnoreCase)
Gets the declared method.
|
||||||||
static <T> String |
getFieldName(Class<T> type,
String name,
boolean equalsIgnoreCase)
Gets the declared field name as String.
|
||||||||
static <T> String |
getFieldName(T type,
String name,
boolean equalsIgnoreCase)
Gets the declared field name as String.
|
||||||||
static <T,V> V |
getFieldValue(T type,
String name,
boolean equalsIgnoreCase)
Gets the field value.
|
||||||||
static Class |
getGenericSupertype(Class type)
Gets the generic supertype.
|
||||||||
static Class |
getGenericSupertype(Class type,
int index)
Gets the generic supertype.
|
||||||||
static Method |
getMethod0(Class c,
String name,
Class... parameterTypes)
Invokes private
Class.getMethod0() without throwing
NoSuchMethodException. |
||||||||
static <T> List<String> |
getMethodsThatHas(T type,
Class<? extends Annotation> annotation)
Gets the methods that has.
|
||||||||
static Class[] |
getSuperclasses(Class type)
Returns all superclasses.
|
||||||||
static Field[] |
getSupportedFields(Class clazz)
Gets the supported fields.
|
||||||||
static Field[] |
getSupportedFields(Class clazz,
Class limit)
Gets the supported fields.
|
||||||||
static Method[] |
getSupportedMethods(Class clazz)
Gets the supported methods.
|
||||||||
static Method[] |
getSupportedMethods(Class clazz,
Class limit)
Returns a
Method array of the methods to which instances of
the specified respond except for those methods defined in the class
specified by limit or any of its superclasses. |
||||||||
static <T> boolean |
has(T type,
String methodName,
boolean equalsIgnoreCase,
Class<? extends Annotation> annotation)
Checks the method for the given type of annotation, whether it contains
it.
|
||||||||
static Object |
invoke(Class c,
Object obj,
String method,
Class[] paramClasses,
Object[] params)
Invokes accessible method of an object.
|
||||||||
static Object |
invoke(Class c,
Object obj,
String method,
Object[] params)
Invoke.
|
||||||||
static Object |
invoke(Object obj,
String method,
Class[] paramClasses,
Object[] params)
Invokes accessible method of an object.
|
||||||||
static Object |
invoke(Object obj,
String method,
Object[] params)
Invokes accessible method of an object without specifying parameter
types.
|
||||||||
static Object |
invokeDeclared(Class c,
Object obj,
String method,
Class[] paramClasses,
Object[] params)
Invokes any method of a class, even private ones.
|
||||||||
static Object |
invokeDeclared(Class c,
Object obj,
String method,
Object[] params)
Invoke declared.
|
||||||||
static Object |
invokeDeclared(Object obj,
String method,
Class[] paramClasses,
Object[] params)
Invokes any method of a class suppressing java access checking.
|
||||||||
static Object |
invokeDeclared(Object obj,
String method,
Object[] params)
Invoke declared.
|
||||||||
static boolean |
isAssignableFrom(Member member1,
Member member2)
Returns
true if the first member is accessible from second
one. |
||||||||
static boolean |
isBeanProperty(Method method)
Returns
true if method is a bean property. |
||||||||
static boolean |
isBeanPropertyGetter(Method method)
Returns
true if method is bean getter. |
||||||||
static boolean |
isBeanPropertySetter(Method method)
Returns
true if method is bean setter. |
||||||||
static boolean |
isInstanceOf(Object o,
Class target)
Dynamic version of
instanceof. |
||||||||
static boolean |
isInterfaceImpl(Class thisClass,
Class targetInterface)
Returns
true if provided class is interface implementation. |
||||||||
static boolean |
isObjectMethod(Method method)
Returns
true if method defined in Object class. |
||||||||
static boolean |
isPublic(Class c)
Returns
true if class is public. |
||||||||
static boolean |
isPublic(Member member)
Returns
true if class member is public. |
||||||||
static boolean |
isPublicPublic(Member member)
Returns
true if class member is public and if its declaring
class is also public. |
||||||||
static boolean |
isSubclass(Class thisClass,
Class target)
Determines if first class match the destination and simulates kind of
instanceof. |
||||||||
static boolean |
isUserDefinedMethod(Method method)
Returns
true if method is user defined and not defined in
Object class. |
||||||||
static Object |
newInstance(Class type)
Creates new instances including for common mutable classes that do not
have a default constructor.
|
||||||||
static Object |
readAnnotationValue(Annotation annotation,
String name)
Reads annotation value.
|
||||||||
static <T> boolean |
setFieldValue(T type,
String name,
String value)
Sets the field value by converting the string type of value to the
required type of the field.
|
||||||||
static <T,V> void |
setFieldValue(T type,
String name,
V value)
Sets the field value.
|
||||||||
static Class |
toClass(Type type)
Returns
Class for the given type.Examples:
Copyright © 2016 utils4j. All Rights Reserved. |