Checks the class to have the given annotation. - Java java.lang.annotation

Java examples for java.lang.annotation:Class Annotation

Description

Checks the class to have the given annotation.

Demo Code


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

public class Main {


    /**/* w  w  w  . j  a  v a 2 s .co m*/
     * Checks the class to have the given annotation.
     * 
     * @param clazz
     *            The class to check.
     * @param annotation
     *            The annotation to check.
     * @return True if class has annotation. False otherwise.
     */
    public static boolean hasAnnotation(Class<?> clazz,
            Class<? extends Annotation> annotation) {
        Annotation found = clazz.getAnnotation(annotation);
        return found != null;
    }
}

Related Tutorials