public final class ReflectionUtils extends Object
ReflectionUtils contains methods for performing
common reflexive operations not found in Java's default API.| Modifier and Type | Method and Description |
|---|---|
static void |
consumeFieldsRecursively(Class<?> clazz,
FieldConsumer consumer)
Applies a given consumer to every field returned by
getFieldsRecursively(). |
static Class<?> |
getClass(Type type)
Returns the Class<?> object for this Type.
|
static List<Field> |
getFieldsRecursively(Class<?> clazz)
Returns all the instance fields of a given class, going up throughout it's hierarchy until reaching the
Object class. |
static List<Field> |
getFieldsRecursivelyExceptJavaClasses(Class<?> clazz)
Returns all the instance fields of a given class, going up throughout it's hierarchy until reaching any Java class.
|
static List<Field> |
getImmediateFields(Class<?> clazz)
Returns all the immediate declared instance fields of a given class.
|
static boolean |
isBaseClass(Class<?> clazz)
Returns true whether clazz is a base class or not.
|
static boolean |
isInnerClass(Class<?> clazz)
Returns whether clazz is an inner class (either anonymous, method local or non-static nested).
|
static boolean |
isJavaClass(Class<?> clazz)
Returns true whether clazz is a Java class or not.
|
public static boolean isInnerClass(Class<?> clazz)
clazz - the class to be evaluatedpublic static List<Field> getImmediateFields(Class<?> clazz)
List rather than an array.clazz - the class to be evaluatedList with all the class's immediate declared instance fieldspublic static List<Field> getFieldsRecursivelyExceptJavaClasses(Class<?> clazz)
isJavaClass()).
For example, the internal array inside String class will not be returned if you class extends String.clazz - the class to be evaluatedList with all the class's fieldspublic static List<Field> getFieldsRecursively(Class<?> clazz)
Object class.
The method selects all non-static non-synthetic declared fields.
If the class used is a base class (see isBaseClass()) the list will be empty.clazz - the class to be evaluatedList with all the class's fieldspublic static void consumeFieldsRecursively(Class<?> clazz, FieldConsumer consumer)
getFieldsRecursively().
Easy to use as it unchecks every excpetion thrown in the process.clazz - The class to be evaluatedconsumer - The function to be run for each fieldpublic static boolean isBaseClass(Class<?> clazz)
Object class.clazz - the class to be evaluatedpublic static boolean isJavaClass(Class<?> clazz)
isBaseClass())
clazz - the class to be evaluatedCopyright © 2015. All rights reserved.