Class has Annotation - Java java.lang.annotation

Java examples for java.lang.annotation:Class Annotation

Description

Class has Annotation

Demo Code


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

public class Main {
    public static void main(String[] argv) throws Exception {
        Class clas = String.class;
        Class annotationClass = String.class;
        System.out.println(hasAnnotation(clas, annotationClass));
    }/*from w w  w  .  java 2  s. c  o  m*/

    public static boolean hasAnnotation(Class clas, Class annotationClass) {
        boolean has = false;
        Annotation a = clas.getAnnotation(annotationClass);
        return a == null ? false : true;
    }
}

Related Tutorials