Returns true if any annotation in parameter Annotations matches annotation Class. - Java java.lang.annotation

Java examples for java.lang.annotation:Class Annotation

Description

Returns true if any annotation in parameter Annotations matches annotation Class.

Demo Code


//package com.java2s;
import java.lang.annotation.Annotation;

public class Main {
    /**/*from   ww w .  j  a v a2  s .  c  o m*/
     * Returns true if any annotation in parameterAnnotations matches annotationClass.
     * 
     * @param parameterAnnotations Annotations to inspect.
     * @param annotationClass      Annotation to find.
     * 
     * @return  true if any annotation in parameterAnnotations matches annotationClass, else false.
     */
    private static boolean hasAnnotation(Annotation[] parameterAnnotations,
            Class<? extends Annotation> annotationClass) {
        for (Annotation annotation : parameterAnnotations) {
            if (annotation.annotationType().equals(annotationClass)) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials