public final class ReflectionUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.lang.Class<?> |
boxType(java.lang.Class<?> type) |
static java.util.List<java.lang.reflect.Field> |
collectFields(java.lang.Class<?> clazz) |
static <T> boolean |
compareFields(T defaultSettings,
T newSettings,
Predicate<? super java.lang.reflect.Field> useField) |
static <T> boolean |
comparePublicNonFinalFields(T first,
T second) |
static void |
copyFields(java.lang.reflect.Field [] fields,
java.lang.Object from,
java.lang.Object to) |
static boolean |
copyFields(java.lang.reflect.Field [] fields,
java.lang.Object from,
java.lang.Object to,
DifferenceFilter<?> diffFilter) |
static void |
copyFieldValue(java.lang.Object from,
java.lang.Object to,
java.lang.reflect.Field field) |
static <T> T |
createInstance(java.lang.reflect.Constructor<T> constructor,
java.lang.Object... args) |
static java.lang.String |
declarationToString(java.lang.reflect.GenericDeclaration anInterface) |
static java.lang.reflect.Field |
findAssignableField(java.lang.Class<?> clazz,
java.lang.Class<?> fieldType,
java.lang.String fieldName) |
static java.lang.Class<?> |
findCallerClass(int framesToSkip)
Returns the class this method was called 'framesToSkip' frames up the caller hierarchy.
|
static java.lang.reflect.Field |
findField(java.lang.Class<?> clazz,
java.lang.Class<?> type,
java.lang.String name) |
static java.lang.reflect.Field |
findFieldInHierarchy(java.lang.Class<?> rootClass,
java.util.function.Predicate<? super java.lang.reflect.Field> checker) |
static java.lang.reflect.Method |
findMethod(java.util.Collection<java.lang.reflect.Method> methods,
java.lang.String name,
java.lang.Class<?>... parameters) |
static java.lang.Class<?> |
forName(java.lang.String fqn) |
static java.lang.reflect.Type [] |
getActualTypeArguments(java.lang.reflect.ParameterizedType parameterizedType) |
static java.lang.Class<?> |
getCallerClass(int stackFrameCount) |
static java.util.List<java.lang.reflect.Field> |
getClassDeclaredFields(java.lang.Class<?> aClass) |
static java.util.List<java.lang.reflect.Method> |
getClassDeclaredMethods(java.lang.Class<?> aClass) |
static java.util.List<java.lang.reflect.Method> |
getClassDeclaredMethods(java.lang.Class<?> aClass,
boolean includeSynthetic) |
static java.util.List<java.lang.reflect.Method> |
getClassPublicMethods(java.lang.Class<?> aClass) |
static java.util.List<java.lang.reflect.Method> |
getClassPublicMethods(java.lang.Class<?> aClass,
boolean includeSynthetic) |
static java.lang.reflect.Field |
getDeclaredField(java.lang.Class<?> aClass,
java.lang.String name) |
static java.lang.reflect.Method |
getDeclaredMethod(java.lang.Class<?> aClass,
java.lang.String name,
java.lang.Class<?>... parameters) |
static <T> java.lang.reflect.Constructor<T> |
getDefaultConstructor(java.lang.Class<T> aClass) |
static <T> T |
getField(java.lang.Class<?> objectClass,
java.lang.Object object,
java.lang.Class<T> fieldType,
java.lang.String fieldName) |
static <T> T |
getFieldValue(java.lang.reflect.Field field,
java.lang.Object object) |
static java.lang.Class<?> |
getGrandCallerClass() |
static java.lang.reflect.Method |
getMethod(java.lang.Class<?> aClass,
java.lang.String name,
java.lang.Class<?>... parameters) |
static java.lang.Class<?> |
getMethodDeclaringClass(java.lang.Class<?> instanceClass,
java.lang.String methodName,
java.lang.Class<?>... parameters) |
static java.lang.Class<?> |
getRawType(java.lang.reflect.Type type) |
static <T> T |
getStaticFieldValue(java.lang.Class<?> objectClass,
java.lang.Class<T> fieldType,
java.lang.String fieldName) |
static <T,V> java.lang.reflect.Field |
getTheOnlyVolatileInstanceFieldOfClass(java.lang.Class<T> ownerClass,
java.lang.Class<V> fieldType) |
static boolean |
isAssignable(java.lang.Class<?> ancestor,
java.lang.Class<?> descendant) |
static boolean |
isInstanceField(java.lang.reflect.Field field) |
static <T> T |
newInstance(java.lang.Class<T> aClass)
Like
Class.newInstance() but also handles private classes |
static <T> T |
newInstance(java.lang.Class<T> aClass,
boolean isKotlinDataClassesSupported) |
static void |
resetField(java.lang.Class<?> clazz,
java.lang.Class<?> type,
java.lang.String name) |
static void |
resetField(java.lang.Object object,
java.lang.Class<?> type,
java.lang.String name) |
static void |
resetField(java.lang.Object object,
java.lang.reflect.Field field) |
static void |
resetField(java.lang.Object object,
java.lang.String name) |
static java.lang.reflect.Type |
resolveVariable(java.lang.reflect.TypeVariable<?> variable,
java.lang.Class<?> classType) |
static java.lang.reflect.Type |
resolveVariable(java.lang.reflect.TypeVariable<?> variable,
java.lang.Class<?> classType,
boolean resolveInInterfacesOnly) |
static java.lang.reflect.Type |
resolveVariableInHierarchy(java.lang.reflect.TypeVariable<?> variable,
java.lang.Class<?> aClass) |
static <T> boolean |
setField(java.lang.Class<?> objectClass,
java.lang.Object object,
java.lang.Class<T> fieldType,
java.lang.String fieldName,
T value) |
static java.lang.Class<?> |
substituteGenericType(java.lang.reflect.Type genericType,
java.lang.reflect.Type classType) |
public static java.lang.reflect.Type resolveVariable(java.lang.reflect.TypeVariable<?> variable, java.lang.Class<?> classType)
public static java.lang.reflect.Type resolveVariable(java.lang.reflect.TypeVariable<?> variable, java.lang.Class<?> classType, boolean resolveInInterfacesOnly)
public static java.lang.String declarationToString(java.lang.reflect.GenericDeclaration anInterface)
public static java.lang.Class<?> getRawType(java.lang.reflect.Type type)
public static java.lang.reflect.Type [] getActualTypeArguments(java.lang.reflect.ParameterizedType parameterizedType)
public static java.lang.Class<?> substituteGenericType(java.lang.reflect.Type genericType, java.lang.reflect.Type classType)
public static java.util.List<java.lang.reflect.Field> collectFields(java.lang.Class<?> clazz)
public static java.lang.reflect.Field findField(java.lang.Class<?> clazz, java.lang.Class<?> type, java.lang.String name) throws java.lang.NoSuchFieldException
java.lang.NoSuchFieldException
public static java.lang.reflect.Field findAssignableField(java.lang.Class<?> clazz, java.lang.Class<?> fieldType, java.lang.String fieldName) throws java.lang.NoSuchFieldException
java.lang.NoSuchFieldException
public static java.lang.reflect.Field findFieldInHierarchy(java.lang.Class<?> rootClass, java.util.function.Predicate<? super java.lang.reflect.Field> checker)
public static void resetField(java.lang.Class<?> clazz, java.lang.Class<?> type, java.lang.String name)
public static void resetField(java.lang.Object object, java.lang.Class<?> type, java.lang.String name)
public static void resetField(java.lang.Object object, java.lang.String name)
public static void resetField(java.lang.Object object, java.lang.reflect.Field field)
public static java.lang.reflect.Method findMethod(java.util.Collection<java.lang.reflect.Method> methods, java.lang.String name, java.lang.Class<?>... parameters)
public static java.lang.reflect.Method getMethod(java.lang.Class<?> aClass, java.lang.String name, java.lang.Class<?>... parameters)
public static java.lang.reflect.Method getDeclaredMethod(java.lang.Class<?> aClass, java.lang.String name, java.lang.Class<?>... parameters)
public static java.lang.reflect.Field getDeclaredField(java.lang.Class<?> aClass, java.lang.String name)
public static java.util.List<java.lang.reflect.Method> getClassPublicMethods(java.lang.Class<?> aClass)
public static java.util.List<java.lang.reflect.Method> getClassPublicMethods(java.lang.Class<?> aClass, boolean includeSynthetic)
public static java.util.List<java.lang.reflect.Method> getClassDeclaredMethods(java.lang.Class<?> aClass)
public static java.util.List<java.lang.reflect.Method> getClassDeclaredMethods(java.lang.Class<?> aClass, boolean includeSynthetic)
public static java.util.List<java.lang.reflect.Field> getClassDeclaredFields(java.lang.Class<?> aClass)
public static java.lang.Class<?> getMethodDeclaringClass(java.lang.Class<?> instanceClass, java.lang.String methodName, java.lang.Class<?>... parameters)
public static <T> T getField(java.lang.Class<?> objectClass, java.lang.Object object, java.lang.Class<T> fieldType, java.lang.String fieldName)
public static <T> T getStaticFieldValue(java.lang.Class<?> objectClass, java.lang.Class<T> fieldType, java.lang.String fieldName)
public static <T> T getFieldValue(java.lang.reflect.Field field, java.lang.Object object)
public static boolean isInstanceField(java.lang.reflect.Field field)
public static <T> boolean setField(java.lang.Class<?> objectClass, java.lang.Object object, java.lang.Class<T> fieldType, java.lang.String fieldName, T value)
public static java.lang.reflect.Type resolveVariableInHierarchy(java.lang.reflect.TypeVariable<?> variable, java.lang.Class<?> aClass)
public static <T> java.lang.reflect.Constructor<T> getDefaultConstructor(java.lang.Class<T> aClass)
public static <T> T newInstance(java.lang.Class<T> aClass)
Class.newInstance()
but also handles private classespublic static <T> T newInstance(java.lang.Class<T> aClass, boolean isKotlinDataClassesSupported)
public static <T> T createInstance(java.lang.reflect.Constructor<T> constructor, java.lang.Object... args)
public static java.lang.Class<?> getGrandCallerClass()
public static java.lang.Class<?> getCallerClass(int stackFrameCount)
public static void copyFields(java.lang.reflect.Field [] fields, java.lang.Object from, java.lang.Object to)
public static boolean copyFields(java.lang.reflect.Field [] fields, java.lang.Object from, java.lang.Object to, DifferenceFilter<?> diffFilter)
public static <T> boolean comparePublicNonFinalFields(T first, T second)
public static <T> boolean compareFields(T defaultSettings, T newSettings, Predicate<? super java.lang.reflect.Field> useField)
public static void copyFieldValue(java.lang.Object from, java.lang.Object to, java.lang.reflect.Field field) throws java.lang.IllegalAccessException
java.lang.IllegalAccessException
public static java.lang.Class<?> forName(java.lang.String fqn)
public static java.lang.Class<?> boxType(java.lang.Class<?> type)
public static <T,V> java.lang.reflect.Field getTheOnlyVolatileInstanceFieldOfClass(java.lang.Class<T> ownerClass, java.lang.Class<V> fieldType)
public static java.lang.Class<?> findCallerClass(int framesToSkip)
public static boolean isAssignable(java.lang.Class<?> ancestor, java.lang.Class<?> descendant)