public class ReflectionUtil extends Object
Utility class that uses java.lang.reflect standard library.
It provides easy access to the standard reflect methods that are
needed usually when dealing with generic object types.
- Stripped down to only needed methods -
| Modifier and Type | Method and Description |
|---|---|
static Class<?> |
getClass(Type type)
Returns the
Class object associated with the given Type
depending on its fully qualified name. |
static String |
getClassName(Type type)
Type#toString() value is the fully qualified class name prefixed
with TYPE_CLASS_NAME_PREFIX. |
static Class<?> |
getGenericClass(Field field) |
static Type[] |
getParameterizedTypes(Object object)
Returns an array of
Type objects representing the actual type
arguments to this object. |
static Field |
getSuperField(Class clazz,
String name) |
public static String getClassName(Type type)
Type#toString() value is the fully qualified class name prefixed
with TYPE_CLASS_NAME_PREFIX. This method will substring it, for it to be eligible
for Class.forName(String).type - the Type value whose class name is needed.String class name of the invoked type.Object.getClass()public static Class<?> getClass(Type type) throws ClassNotFoundException
Class object associated with the given Type
depending on its fully qualified name.type - the Type whose Class is needed.Class object for the class with the specified name.ClassNotFoundException - if the class cannot be located.getClassName(Type)public static Type[] getParameterizedTypes(Object object)
Type objects representing the actual type
arguments to this object.
If the returned value is null, then this object represents a non-parameterized
object.object - the object whose type arguments are needed.Type objects representing the actual type
arguments to this object.Class.getGenericSuperclass(),
ParameterizedType.getActualTypeArguments()public static Field getSuperField(Class clazz, String name) throws NoSuchFieldException
NoSuchFieldExceptionCopyright © 2018. All rights reserved.