public class ReflectionUtils extends Object
Provides methods to help with reflective operations
| Modifiers | Name | Description |
|---|---|---|
static Map<Class<?>, Class<?>> |
PRIMITIVE_TYPE_COMPATIBLE_CLASSES |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static Class |
forName(String className, ClassLoader classLoader) |
|
public static PropertyDescriptor[] |
getPropertiesOfType(Class<?> clazz, Class<?> propertyType)Retrieves all the properties of the given class for the given type |
<T> |
public static T |
instantiate(Class<T> clazz)Instantiates an object catching any relevant exceptions and rethrowing as a runtime exception |
|
public static boolean |
isAssignableFrom(Class<?> leftType, Class<?> rightType) |
|
public static boolean |
isGetter(String name, Class<?>[] args)Returns true if the name of the method specified and the number of arguments make it a javabean property |
|
public static boolean |
isSetter(String name, Class[] args) |
|
public static void |
makeAccessible(Field field)Make the given field accessible, explicitly setting it accessible if necessary. |
|
public static void |
makeAccessible(Method method)Make the given method accessible, explicitly setting it accessible if necessary. |
Retrieves all the properties of the given class for the given type
clazz - The class to retrieve the properties frompropertyType - The type of the properties you wish to retrieveInstantiates an object catching any relevant exceptions and rethrowing as a runtime exception
clazz - The class
Tests weather or not the left hand type is compatible with the right hand type in Groovy terms, i.e. can the left type be assigned a value of the right hand type in Groovy.
This handles Java primitive type equivalence and uses isAssignableFrom for all other types, with a bit of magic for native types and polymorphism i.e. Number assigned an int. If either parameter is null an exception is thrown
leftType - The type of the left hand part of a notional assignmentrightType - The type of the right hand part of a notional assignmentReturns true if the name of the method specified and the number of arguments make it a javabean property
name - True if it's a Javabean propertyargs - The arguments Make the given field accessible, explicitly setting it accessible if necessary.
The setAccessible(true) method is only called when actually necessary,
to avoid unnecessary conflicts with a JVM SecurityManager (if active).
Based on the same method in Spring core.
field - the field to make accessible Make the given method accessible, explicitly setting it accessible if necessary.
The setAccessible(true) method is only called when actually necessary,
to avoid unnecessary conflicts with a JVM SecurityManager (if active).
Based on the same method in Spring core.
method - the method to make accessible