Check if class has Annotation - Java java.lang.annotation

Java examples for java.lang.annotation:Class Annotation

Description

Check if class has Annotation

Demo Code


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

public class Main {
    public static boolean hasAnnotation(Method method,
            Class<? extends Annotation> annotation) {
        return method != null && method.isAnnotationPresent(annotation);
    }//from  ww w .ja  va 2s . c o m

    public static boolean hasAnnotation(Class<?> clazz,
            Class<? extends Annotation> annotation) {
        return clazz != null && clazz.isAnnotationPresent(annotation);
    }
}

Related Tutorials