Close

Java Reflection - Class.isAnnotationPresent() Examples

Java Reflection Java Java API 


Class:

java.lang.Class

java.lang.Objectjava.lang.Objectjava.lang.Classjava.lang.Classjava.io.SerializableSerializablejava.lang.reflect.GenericDeclarationGenericDeclarationjava.lang.reflect.TypeTypejava.lang.reflect.AnnotatedElementAnnotatedElementLogicBig

Method:

public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
Parameters:
annotationClass - the Class object corresponding to the annotation type
Returns:
true if an annotation for the specified annotation type is present on this element, else false

Examples


package com.logicbig.example.clazz;

import java.io.LineNumberInputStream;

public class IsAnnotationPresentExample {

public static void main(String... args) {
Class<LineNumberInputStream> c = LineNumberInputStream.class;
boolean b = c.isAnnotationPresent(Deprecated.class);
System.out.println(b);
}
}

Output

true




See Also