is Annotation Exists on Class - Java java.lang.annotation

Java examples for java.lang.annotation:Class Annotation

Description

is Annotation Exists on Class

Demo Code


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

public class Main {

    public static boolean isExists(Class<?> clazz, Annotation annotation) {
        Annotation existingAnnotation = clazz.getAnnotation(annotation
                .annotationType());//  w ww.jav a  2 s  . com
        return existingAnnotation != null;
    }

    public static boolean isExists(Method method, Annotation annotation) {
        Annotation existingAnnotation = method.getAnnotation(annotation
                .annotationType());
        return existingAnnotation != null;
    }

    public static boolean isExists(Field field, Annotation annotation) {
        Annotation existingAnnotation = field.getAnnotation(annotation
                .annotationType());
        return existingAnnotation != null;
    }
}

Related Tutorials