Close

Java Reflection - Class.isAnnotation() 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 isAnnotation()
Returns:
true if this class object represents an annotation type; false otherwise. Note that if this method returns true, Class.isInterface() would also return true, as all annotation types are also interfaces.


Examples


package com.logicbig.example.clazz;

public class IsAnnotationExample {

public static void main(String... args) {
Class<Deprecated> c = Deprecated.class;
System.out.println("isAnnotation: "+c.isAnnotation());
System.out.println("isInterface: "+c.isInterface());
}
}

Output

isAnnotation: true
isInterface: true




package com.logicbig.example.clazz;

public class IsAnnotationExample2 {

public static void main(String... args) {
Class<Runnable> c = Runnable.class;
System.out.println("isAnnotation: " + c.isAnnotation());
System.out.println("isInterface: " + c.isInterface());
}
}

Output

isAnnotation: false
isInterface: true




See Also