Sunday 20 March 2022

Java: How to check whether given class is an annotation or not?

'java.lang.Class' provides 'isAnnotation' method which return true, if the given class is an annotation, else false.

 

ClassAnnotationCheck.java

package com.sample.app;

public class ClassAnnotationCheck {
	
	public static void main(String[] args) {
		System.out.println("Is System class represent an annotation : "+ System.class.isAnnotation());
		System.out.println("Is Deprecated class represent an annotation : "+ Deprecated.class.isAnnotation());
	}

}

Output

Is System class represent an annotation : false
Is Deprecated class represent an annotation : true



 

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment