is Annotation Present - Java java.lang.annotation

Java examples for java.lang.annotation:Annotation Attribute

Description

is Annotation Present

Demo Code


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

public class Main {


    public static boolean isAnnotationPresent(Class<?> clazz,
            Class<? extends Annotation> annotationClass, boolean recursive) {

        boolean isPresent = clazz.isAnnotationPresent(annotationClass);
        if (isPresent || !recursive
                || clazz.getSuperclass().equals(Object.class)) {
            return isPresent;
        } else {/*  ww w.j a v  a2  s.  co m*/
            return isAnnotationPresent(clazz.getSuperclass(),
                    annotationClass, recursive);
        }

    }
}

Related Tutorials