Class AnnotationUtils
- java.lang.Object
-
- org.apache.commons.lang3.AnnotationUtils
-
public class AnnotationUtils extends java.lang.ObjectHelper methods for working with
Annotationinstances.This class contains various utility methods that make working with annotations simpler.
Annotationinstances are always proxy objects; unfortunately dynamic proxies cannot be depended upon to know how to implement certain methods in the same manner as would be done by "natural"Annotations. The methods presented in this class can be used to avoid that possibility. It is of course also possible for dynamic proxies to actually delegate their e.g.Annotation.equals(Object)/Annotation.hashCode()/Annotation.toString()implementations toAnnotationUtils.#ThreadSafe#
- Since:
- 3.0
-
-
Constructor Summary
Constructors Constructor Description AnnotationUtils()AnnotationUtilsinstances should NOT be constructed in standard programming.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanequals(java.lang.annotation.Annotation a1, java.lang.annotation.Annotation a2)Checks if two annotations are equal using the criteria for equality presented in theAnnotation.equals(Object)API docs.static inthashCode(java.lang.annotation.Annotation a)Generate a hash code for the given annotation using the algorithm presented in theAnnotation.hashCode()API docs.static booleanisValidAnnotationMemberType(java.lang.Class<?> type)Checks if the specified type is permitted as an annotation member.static java.lang.StringtoString(java.lang.annotation.Annotation a)Generate a string representation of an Annotation, as suggested byAnnotation.toString().
-
-
-
Method Detail
-
equals
public static boolean equals(java.lang.annotation.Annotation a1, java.lang.annotation.Annotation a2)Checks if two annotations are equal using the criteria for equality presented in the
Annotation.equals(Object)API docs.- Parameters:
a1- the first Annotation to compare,nullreturnsfalseunless both arenulla2- the second Annotation to compare,nullreturnsfalseunless both arenull- Returns:
trueif the two annotations areequalor bothnull
-
hashCode
public static int hashCode(java.lang.annotation.Annotation a)
Generate a hash code for the given annotation using the algorithm presented in the
Annotation.hashCode()API docs.- Parameters:
a- the Annotation for a hash code calculation is desired, notnull- Returns:
- the calculated hash code
- Throws:
java.lang.RuntimeException- if anExceptionis encountered during annotation member accessjava.lang.IllegalStateException- if an annotation method invocation returnsnull
-
toString
public static java.lang.String toString(java.lang.annotation.Annotation a)
Generate a string representation of an Annotation, as suggested by
Annotation.toString().- Parameters:
a- the annotation of which a string representation is desired- Returns:
- the standard string representation of an annotation, not
null
-
isValidAnnotationMemberType
public static boolean isValidAnnotationMemberType(java.lang.Class<?> type)
Checks if the specified type is permitted as an annotation member.
The Java language specification only permits certain types to be used in annotations. These include
String,Class, primitive types,Annotation,Enum, and single-dimensional arrays of these types.- Parameters:
type- the type to check,null- Returns:
trueif the type is a valid type to use in an annotation
-
-