Java record -86-reflection API usage Example advanced 2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.