Get Constructor, Fields, Methods, Annonation of Class By Java Reflection API

Constructor


Only For Public constructor
Constructor[] constructors = MyClass.class.getConstructors();

For All constructor including private
Constructor[]constructors= MyClass.class.getDeclaredConstructors();

Fields

Field[] method = MyClass.class.getFields();

Get All Fileds Exclude the inherited fields
Field[] method = MyClass.class.getDeclaredFields();

Methods
Method[] method = MyClass.class.getMethods();
Method[] method = MyClass.class.getDeclaredMethods();

Annotations
Annotation[] annotations = MyClass.class.getAnnotations();
Annotation[] annotations = MyClass.class.getDeclaredAnnotations();

Comments