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()); } }}