public class ReflectionUtils extends Object
Modifier and Type | Method and Description |
---|---|
static int |
getClassDistance(Class<?> parent,
Class<?> child)
The number of hierarchy classes between two classes.
|
static Object |
getDeclaredFieldValue(String fieldName,
Object instance)
Gets the value of a field
|
static Object |
getDeclaredStaticFieldValue(String fieldName,
Class<?> klass)
Gets the value of a field
|
static <E extends Enum> |
getEnumValues(Class<?> enumClass)
Gets all enum values via reflection
|
static Object |
getFieldValue(Field field,
Object instance)
Gets the value of a field
|
static Object |
getFieldValue(String fieldName,
Object instance)
Gets the value of a field
|
static Attributes |
getManifestAttributes() |
static Object |
getStaticFieldValue(String fieldName,
Class<?> klass)
Gets the value of a field
|
static boolean |
hasDefaultConstructor(Class<?> klass)
Returns true if the class has a default constructor
|
static Object |
invokeMethod(Object target,
String functionName,
Object... args)
Calls a function and returns its output
|
static boolean |
isAbstractOrInterface(Class<?> klass) |
static boolean |
isAssignableTo(Class<?> from,
Class<?> to)
More powerful variant of Class.isAssignableFrom that supports primitives.
|
static boolean |
isPrimitiveWrapperOf(Class<?> targetClass,
Class<?> primitive)
Returns true if the class is a primitive wrapper
|
static Object |
newInstance(Class<?> klass,
Object... args)
Creates a new class instance.
|
static void |
setDeclaredFieldValue(Object instance,
String fieldName,
Object value)
Sets the field value
|
static void |
setFieldValue(Object instance,
String fieldName,
Object value)
Sets the field value
|
public static Attributes getManifestAttributes()
public static Object getDeclaredFieldValue(String fieldName, Object instance)
fieldName
- the field nameinstance
- the instancepublic static Object getDeclaredStaticFieldValue(String fieldName, Class<?> klass)
fieldName
- the field nameklass
- the classpublic static Object getStaticFieldValue(String fieldName, Class<?> klass)
fieldName
- the field nameklass
- the classpublic static Object getFieldValue(String fieldName, Object instance)
fieldName
- the field nameinstance
- the instancepublic static void setDeclaredFieldValue(Object instance, String fieldName, Object value)
instance
- the objectfieldName
- the field namevalue
- the valuepublic static void setFieldValue(Object instance, String fieldName, Object value)
instance
- the objectfieldName
- the field namevalue
- the valuepublic static Object getFieldValue(Field field, Object instance)
field
- the fieldinstance
- the instancepublic static boolean isPrimitiveWrapperOf(Class<?> targetClass, Class<?> primitive)
targetClass
- target classprimitive
- primitive classpublic static boolean isAssignableTo(Class<?> from, Class<?> to)
from
- from classto
- to classpublic static Object newInstance(Class<?> klass, Object... args)
klass
- instantiated classargs
- for primitives, ignored. For classes passed to the constructorpublic static <E extends Enum> E[] getEnumValues(Class<?> enumClass) throws NoSuchFieldException, IllegalAccessException
E
- the enum classenumClass
- the enum classNoSuchFieldException
- triggered by reflectionIllegalAccessException
- triggered by reflectionpublic static Object invokeMethod(Object target, String functionName, Object... args)
target
- The objectfunctionName
- the functionpublic static boolean hasDefaultConstructor(Class<?> klass)
klass
- the classpublic static boolean isAbstractOrInterface(Class<?> klass)
public static int getClassDistance(Class<?> parent, Class<?> child)
parent
- the parent class or interfacechild
- the child class or interfaceCopyright © 2020–2022 Leibniz Institute for Natural Product Research and Infection Biology - Hans Knöll Institute (HKI). All rights reserved.