编程语言
首页 > 编程语言> > java.beans.BeanInfo

java.beans.BeanInfo

作者:互联网

可用通过BeanInfo接口创建BeanInfo类,并提供关于bean的方法、属性、事件和其他特性的显式信息。

通用方式

BeanInfo beanInfo = Introspector.getBeanInfo(TradeTransaction.class);

其中Introspector类提供了标准方法获取目标Java Bean支持的属性、事件和方法。

java.beans.BeanInfo提供的方法

 

 

测试代码

public class TradeTransaction {
    private String id;//交易ID
    private double price;//交易金额

    public TradeTransaction() {
    }

    public TradeTransaction(String id, double price) {
        super();
        this.id = id;
        this.price = price;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}

 

使用BeanInfo

    public static void main(String[] args) {
        BeanInfo beanInfo;
        try {
            beanInfo = Introspector.getBeanInfo(TradeTransaction.class);
        } catch (IntrospectionException e) {
            throw new IllegalStateException(e.getMessage(), e);
        }

        for (MethodDescriptor methodDescriptor : beanInfo.getMethodDescriptors()) {
            Method method = methodDescriptor.getMethod();
            System.out.println(method.getName());
        }
    }

 

日志

getClass
setPrice
setId
wait
notifyAll
getId
notify
wait
hashCode
getPrice
wait
equals
toString

  

标签:java,String,BeanInfo,price,public,beans,id,TradeTransaction
来源: https://www.cnblogs.com/use-D/p/16648330.html