public class ReflectionUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ReflectionUtils.AnnotationFieldFilter
A
ReflectionUtils.FieldFilter for a given annotation. |
static interface |
ReflectionUtils.DescribedFieldFilter
A
ReflectionUtils.FieldFilter that has a description. |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
createInstanceIfPresent(String classname,
T defaultInstance)
Creates an instance of the class with the given fully qualified name or returns the given default instance if the
class cannot be loaded or instantiated.
|
static Field |
findField(Class<?> type,
ReflectionUtils.DescribedFieldFilter filter)
Finds the field matching the given
ReflectionUtils.DescribedFieldFilter. |
static Field |
findField(Class<?> type,
ReflectionUtils.DescribedFieldFilter filter,
boolean enforceUniqueness)
Finds the field matching the given
ReflectionUtils.DescribedFieldFilter. |
static Field |
findField(Class<?> type,
ReflectionUtils.FieldFilter filter)
Finds the first field on the given class matching the given
ReflectionUtils.FieldFilter. |
static boolean |
isDefaultMethod(Method method)
Back-port of Java 8's
isDefault() method on Method. |
static void |
setField(Field field,
Object target,
Object value)
Sets the given field on the given object to the given value.
|
public static <T> T createInstanceIfPresent(String classname, T defaultInstance)
classname - the fully qualified class name to create an instance for.defaultInstance - the instance to fall back to in case the given class cannot be loaded or instantiated.public static boolean isDefaultMethod(Method method)
isDefault() method on Method.method - must not be null.public static Field findField(Class<?> type, ReflectionUtils.FieldFilter filter)
ReflectionUtils.FieldFilter.type - must not be null.filter - must not be null.public static Field findField(Class<?> type, ReflectionUtils.DescribedFieldFilter filter)
ReflectionUtils.DescribedFieldFilter. Will make sure there's only one field matching the
filter.type - must not be null.filter - must not be null.ReflectionUtils.DescribedFieldFilter or null if none found.IllegalStateException - in case more than one matching field is foundfindField(Class, DescribedFieldFilter, boolean)public static Field findField(Class<?> type, ReflectionUtils.DescribedFieldFilter filter, boolean enforceUniqueness)
ReflectionUtils.DescribedFieldFilter. Will make sure there's only one field matching the
filter in case enforceUniqueness is true.type - must not be null.filter - must not be null.enforceUniqueness - whether to enforce uniqueness of the fieldReflectionUtils.DescribedFieldFilter or null if none found.IllegalStateException - if enforceUniqueness is true and more than one matching field is foundCopyright © 2011-2014–2014 Pivotal Software, Inc.. All rights reserved.