public final class ReflectUtil
extends java.lang.Object
| Constructor and Description |
|---|
ReflectUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
clearAllFields(java.lang.Object object)
Clears, i.e.
|
static void |
clearAllFields(java.lang.Object object,
java.lang.String[] excludedFieldNames)
Clears, i.e.
|
static java.lang.reflect.Field |
findDeclaredField(java.lang.Class<?> clazz,
java.lang.String fieldName)
Get declared field of the given class by name
|
static java.lang.reflect.Method |
findDeclaredMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes)
Get declared method of the given class by Name and input parameter types
|
static java.lang.reflect.Field |
findField(java.lang.Class<?> clazz,
java.lang.String fieldName)
Get the field of the given Class by name.
|
static java.lang.reflect.Method |
findMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes)
Find method of the given class by name and parameter types
|
static java.lang.Object |
getFieldValue(java.lang.Object object,
java.lang.String fieldName)
Returns the value of the visible (i.e.
|
static java.lang.Object |
getInvisibleFieldValue(java.lang.Object object,
java.lang.String fieldName)
Returns the value of the invisible (i.e.
|
static java.lang.String |
getSimplePackageName(java.lang.String qualifiedPackageName)
Get simple package name of the given package
|
static java.lang.String |
getSuperPackageName(java.lang.String qualifiedPackageName)
Get super Package name of the given package
|
static java.lang.Object |
invokeInvisibleMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object... args)
Invokes the invisible (i.e.
|
static java.lang.Object |
invokeMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object... args)
Invokes the visible (i.e.
|
static boolean |
isAssignableFrom(java.lang.Class<?> clazz,
java.lang.String className)
Check if the given Class name is assignable from a real Class
|
static void |
setFieldValue(java.lang.Object object,
java.lang.String fieldName,
java.lang.Object value)
Sets the value of the visible (i.e.
|
static void |
setInvisibleFieldValue(java.lang.Object object,
java.lang.String fieldName,
java.lang.Object value)
Sets the value of the invisible (i.e.
|
public static boolean isAssignableFrom(java.lang.Class<?> clazz,
java.lang.String className)
clazz - the real classclassName - the class nametrue if the clazz is assignable from className, else return
falsepublic static java.lang.reflect.Field findDeclaredField(java.lang.Class<?> clazz,
java.lang.String fieldName)
clazz - the owning of the fieldfieldName - the name of the fieldField of the given class that has the name is the given field name, return
null if there is no such field declared in the given classpublic static java.lang.reflect.Field findField(java.lang.Class<?> clazz,
java.lang.String fieldName)
clazz - the class owning the field to findfieldName - the name of the field to findField of the given class. This field can be declared in the given class or in SuperClass or
Super Interface of the given class, return null if there isn't such a field in the given class
and its super classespublic static java.lang.Object getFieldValue(java.lang.Object object,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalArgumentException,
java.lang.IllegalAccessException
object - the owning of the fieldfieldName - the name of the fieldjava.lang.NoSuchFieldExceptionjava.lang.IllegalArgumentExceptionjava.lang.IllegalAccessExceptionpublic static java.lang.Object getInvisibleFieldValue(java.lang.Object object,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalArgumentException,
java.lang.IllegalAccessException
object - the object owning the fieldfieldName - the name of the field to be accessedjava.lang.NoSuchFieldExceptionjava.lang.IllegalAccessExceptionjava.lang.IllegalArgumentExceptionpublic static void setFieldValue(java.lang.Object object,
java.lang.String fieldName,
java.lang.Object value)
throws java.lang.NoSuchFieldException,
java.lang.IllegalArgumentException,
java.lang.IllegalAccessException
object - the object owning the fieldfieldName - the name of the field to be accessedvalue - the value to be set on the fieldjava.lang.NoSuchFieldExceptionjava.lang.IllegalAccessExceptionjava.lang.IllegalArgumentExceptionpublic static void setInvisibleFieldValue(java.lang.Object object,
java.lang.String fieldName,
java.lang.Object value)
throws java.lang.NoSuchFieldException,
java.lang.IllegalArgumentException,
java.lang.IllegalAccessException
object - the object owning the fieldfieldName - the name of the field to be accessedvalue - the value to be set on the fieldjava.lang.NoSuchFieldExceptionjava.lang.IllegalAccessExceptionjava.lang.IllegalArgumentExceptionpublic static java.lang.reflect.Method findDeclaredMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes)
clazz - the owning of the methodmethodName - the name of the method declared by the given classparameterTypes - input parameter types of the methodMethod that has the given name and given parameter types. Return null if there is
no method like thatpublic static java.lang.reflect.Method findMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes)
throws java.lang.NoSuchMethodException
clazz - the owning of the method to findmethodName - the name of the method need to be foundparameterTypes - input parameter types of the methodMethod that has the given name and given parameter types. Return null if there is
no such method like thatjava.lang.NoSuchMethodExceptionpublic static java.lang.Object invokeMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object... args)
throws java.lang.NoSuchMethodException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException
object - the object owning the methodmethodName - the name of the method to be invokedargs - parameter types of the methodjava.lang.NoSuchMethodExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionpublic static java.lang.Object invokeInvisibleMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object... args)
throws java.lang.NoSuchMethodException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException
object - the object owning the methodmethodName - the name of the method to be invokedargs - the arguments of the methodjava.lang.NoSuchMethodExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionpublic static java.lang.String getSimplePackageName(java.lang.String qualifiedPackageName)
qualifiedPackageName - the given package namepublic static java.lang.String getSuperPackageName(java.lang.String qualifiedPackageName)
qualifiedPackageName - the given package namepublic static void clearAllFields(java.lang.Object object)
throws java.lang.IllegalAccessException
object - the object whose fields are to be clearedjava.lang.IllegalAccessExceptionpublic static void clearAllFields(java.lang.Object object,
java.lang.String[] excludedFieldNames)
throws java.lang.IllegalAccessException
object - the object whose fields are to be clearedexcludedFieldNames - the names of the fields that are to be excluded from clearingjava.lang.IllegalAccessException