mercredi 26 juillet 2017

How to determine (at runtime) if a variable is annotated as deprecated?

This code can check whether a class is deprecated or not

@Deprecated
public classRetentionPolicyExample{

             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 be checked if any variable is annotated as deprecated?

@Deprecated
Stringvariable;





Aucun commentaire:

Enregistrer un commentaire