This code can check if the class is deprecated or not.
@Deprecated
public class RetentionPolicyExample {
public static void main(String[] args){
boolean isDeprecated=false;
if(RetentionPolicyExample.class.getAnnotations().length>0){
isDeprecated= RetentionPolicyExample.class
.getAnnotations()[0].toString()
.contains("Deprecated");
}
System.out.println("is deprecated:"+ isDeprecated);
}
}
But how can one check if a variable is annotated as deprecated?
@Deprecated
String variable;
source
share