Gets the information under the specified class: All Methods and properties
Public class dumpclassinfo { public static void main ( String[] args) throws exception{ //reflection The basic role of api Class<?> classtype = Class.forName ("My.reflect.Customer"); method[] methods = classtype.getdeclaredmethods (); //gets all the methods under the specified class, Contains private methods. (All methods at runtime) for (Method method : methods) { system.out.println (method); } Field[] fields = classtype.getdeclaredfields (); //gets all the properties under the specified class, including private properties. (All properties at runtime) &NBSP;&NBSP;&NBSP;&NBSP;&NBSp; for (Field field : fields) { system.out.println (field); } }}class Customer{ private long id; private String name; private int age; public customer () {} public Customer (string name, int age) { this.name = name; this.age = age; } public long getid () { Return id; } public void setid (Long id) { &nBsp; this.id = id; } public string getname () { return name; } public void setname (String name) { this.name = name; } public int getage () { return age; } public void setage (int age) { this.age = age; }}
The above program output results:
public void My.reflect.Customer.setId (long) public int my.reflect.Customer.getAge () public void My.reflect.Customer.setAge (int) public java.lang.String my.reflect.Customer.getName () public long My.reflect.Customer.getId () public void My.reflect.Customer.setName (java.lang.String) Private long my.reflect.Customer.idprivate java.lang.String my.reflect.Customer.nameprivate int my.reflect.Customer.age
Java record -86-reflection API usage Example advanced 2