Package com.restfb.util
Klasse ReflectionUtils
java.lang.Object
com.restfb.util.ReflectionUtils
A collection of reflection-related utility methods.
- Seit:
- 1.6
- Autor:
- Mark Allen, Igor Kabiljo, Scott Hernandez
-
Verschachtelte Klassen - Übersicht
Modifizierer und TypKlasseBeschreibungstatic class
A field/annotation pair. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic <T> T
createInstance
(Class<T> type) Creates a new instance of the giventype
.static boolean
Reflection-based implementation ofObject.equals(Object)
.static <T extends Annotation>
List<ReflectionUtils.FieldWithAnnotation<T>>findFieldsWithAnnotation
(Class<?> type, Class<T> annotationType) Finds fields on the giventype
and all of its superclasses annotated with annotations of typeannotationType
.static <T extends Annotation>
List<Method>findMethodsWithAnnotation
(Class<?> type, Class<T> annotationType) Finds methods on the giventype
and all of its superclasses annotated with annotations of typeannotationType
.getAccessors
(Class<?> clazz) Gets all accessor methods for the givenclazz
.static Class<?>
For a givenfield
, get its first parameterized type argument.static Class<?>
For a givenfield
, get its second parameterized type argument.static int
Reflection-based implementation ofObject.hashCode()
.static boolean
isPrimitive
(Object object) Is the givenobject
a primitive type or wrapper for a primitive type?static void
static String
Reflection-based implementation ofObject.toString()
.
-
Methodendetails
-
setJson
-
isPrimitive
Is the givenobject
a primitive type or wrapper for a primitive type?- Parameter:
object
- The object to check for primitive-ness.- Gibt zurück:
true
ifobject
is a primitive type or wrapper for a primitive type,false
otherwise.
-
findFieldsWithAnnotation
public static <T extends Annotation> List<ReflectionUtils.FieldWithAnnotation<T>> findFieldsWithAnnotation(Class<?> type, Class<T> annotationType) Finds fields on the giventype
and all of its superclasses annotated with annotations of typeannotationType
.- Typparameter:
T
- The annotation type.- Parameter:
type
- The target type token.annotationType
- The annotation type token.- Gibt zurück:
- A list of field/annotation pairs.
-
findMethodsWithAnnotation
public static <T extends Annotation> List<Method> findMethodsWithAnnotation(Class<?> type, Class<T> annotationType) Finds methods on the giventype
and all of its superclasses annotated with annotations of typeannotationType
.These results are cached to mitigate performance overhead.
- Typparameter:
T
- The annotation type.- Parameter:
type
- The target type token.annotationType
- The annotation type token.- Gibt zurück:
- A list of methods with the given annotation.
- Seit:
- 1.6.11
-
getFirstParameterizedTypeArgument
For a givenfield
, get its first parameterized type argument.For example, a field of type
List<Long>
would have a first type argument ofLong.class
.If the field has no type arguments,
null
is returned.- Parameter:
field
- The field to check.- Gibt zurück:
- The field's first parameterized type argument, or
null
if none exists.
-
getSecondParameterizedTypeArgument
For a givenfield
, get its second parameterized type argument. If the field has no type arguments,null
is returned.- Parameter:
field
- The field to check.- Gibt zurück:
- The field's second parameterized type argument, or
null
if none exists.
-
getAccessors
Gets all accessor methods for the givenclazz
.- Parameter:
clazz
- The class for which accessors are extracted.- Gibt zurück:
- All accessor methods for the given
clazz
.
-
toString
Reflection-based implementation ofObject.toString()
.- Parameter:
object
- The object to convert to a string representation.- Gibt zurück:
- A string representation of
object
. - Löst aus:
IllegalStateException
- If an error occurs while performing reflection operations.
-
hashCode
Reflection-based implementation ofObject.hashCode()
.- Parameter:
object
- The object to hash.- Gibt zurück:
- A hashcode for
object
. - Löst aus:
IllegalStateException
- If an error occurs while performing reflection operations.
-
equals
Reflection-based implementation ofObject.equals(Object)
.- Parameter:
object1
- One object to compare.object2
- Another object to compare.- Gibt zurück:
true
if the objects are equal,false
otherwise.- Löst aus:
IllegalStateException
- If an error occurs while performing reflection operations.
-
createInstance
Creates a new instance of the giventype
.- Typparameter:
T
- Java type to map to.- Parameter:
type
- Type token.- Gibt zurück:
- A new instance of
type
. - Löst aus:
FacebookJsonMappingException
- If an error occurs when creating a new instance (type
is inaccessible, doesn't have a no-arg constructor, etc.)
-