Java: introspector and introspector

Source: Internet
Author: User

Java: introspector and introspector

Attribute Concept

It is not just a field, but its get set method.

This get method has a returned value called an attribute that inherits the getClass method of the Object class.

Package com. swift. demo1; public class Person {String name; int age; String password; 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;} public String getPassword () {return password;} public void setPassword (String password) {this. password = password;} public String getAd () {// This is an attribute. Although no field exists, if no return value is returned, return "getAd ..... ";}}

Attribute count

package com.swift.demo1;import java.beans.BeanInfo;import java.beans.Introspector;import java.beans.PropertyDescriptor;import org.junit.jupiter.api.Test;public class TestIntro {    @Test    public void test1() throws Exception {        BeanInfo info=Introspector.getBeanInfo(Person.class);        PropertyDescriptor[] pds=info.getPropertyDescriptors();        for(PropertyDescriptor des:pds) {            System.out.println(des.getName());        }    }}

Prevents the getClass attribute of the parent class from being used

package com.swift.demo1;import java.beans.BeanInfo;import java.beans.Introspector;import java.beans.PropertyDescriptor;import org.junit.jupiter.api.Test;public class TestIntro {    @Test    public void test1() throws Exception {        BeanInfo info=Introspector.getBeanInfo(Person.class,Object.class);        PropertyDescriptor[] pds=info.getPropertyDescriptors();        for(PropertyDescriptor des:pds) {            System.out.println(des.getName());        }    }}

 

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.