Java Utililty Methods Reflection Annotation

List of utility methods to do Reflection Annotation

Description

The list of methods to do Reflection Annotation are organized into topic(s).

Method

VgetAnnotationValue(final A annotation, final Function valueRetriever, final V defaultValue)
Returns the value of the given annotation using a Function.
if (annotation != null) {
    final V value = valueRetriever.apply(annotation);
    if (defaultValue.getClass().equals(String.class) && !String.class.cast(value).isEmpty()) {
        return value;
    } else if (!defaultValue.getClass().equals(String.class) && value != null) {
        return value;
return defaultValue;
ObjectgetAnnotationValue(Object aObj, String aValue)
Get annotation value of annotation object via reflection
return aObj.getClass().getMethod(aValue).invoke(aObj);
ObjectgetAnnotationValue(Object obj, Class annotation, String field)
Retrieve the value of the annotation
Class<?> cls = getClass(obj);
if (cls.isAnnotationPresent(annotation))
    return invokeMethod(cls.getAnnotation(annotation), field);
else
    return null;
ObjectgetAnnotationWithinHierarchy(Class fsmClass, Class aggregateClass)
Get annotation within hierarchy
while (fsmClass != null) {
    if (getAnnotation(fsmClass, aggregateClass) != null) {
        return getAnnotation(fsmClass, aggregateClass);
    fsmClass = fsmClass.getSuperclass();
return null;
AnnotationgetAnnotationWithMetaAnnotation(AnnotatedElement annotatedElement, Class metaAnnotationType)
get Annotation With Meta Annotation
Annotation[] annotations = annotatedElement.getAnnotations();
for (Annotation annotation : annotations) {
    Class<? extends Annotation> annotationClass = annotation.annotationType();
    if (annotationClass.isAnnotationPresent(metaAnnotationType)) {
        return annotation;
return null;
...