Class isAnnotationPresent() method in Java with Examples
The isAnnotationPresent() method of java.lang.Class class is used to check if an annotation of the specified annotation type is present in this class. The method returns a boolean value stating the same.
public boolean isAnnotationPresent(Class<T> annotationClass)
Parameter: This method accepts a parameter annotationClass which is the type of the annotation to get.
Return Value: This method returns boolean value stating the same.
Exception: This method throws:
- NullPointerException: if the given annotation class is null.
Below programs demonstrate the isAnnotationPresent() method.
Class represented by myClass: class Test If there is any annotation in myClass: true
Class represented by myClass: class Test If there is any annotation in myClass: false
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.