Java Reflection class get deprecated constructors

Description

Java Reflection class get deprecated constructors

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class Main {
   public static void main(String args[]) throws Exception {
      Class c = Class.forName("java.lang.String");
      Constructor[] cons = c.getConstructors();
      for (Constructor con : cons) {
         Annotation[] anos = con.getDeclaredAnnotations();
         for (Annotation a : anos)
            if (a.toString().contains("Deprecated"))
               System.out.println(con);
      }/*from  www.jav a 2  s . com*/

   }
}



PreviousNext

Related