[英]Get bean property getter or setter by reflection?
Suppose I have a handle on an object of type , and I'm told by configuration that it has a bean property of type int
with the name age
. 假设我有一个类型对象的句柄,我通过配置告诉它它有一个
int
类型的bean属性,名称为age
。 How can I retrieve the getter for this document? 如何检索此文档的getter?
Is there a better way than prepending "get" and capitalizing the "a" in age
, and looking for a method of that name via reflection? 有没有一种更好的方法比在“
age
”中加上“获得”和大写“a”,并通过反思寻找一个名称的方法?
Take a look at java.beans.Introspector
. 看看
java.beans.Introspector
。 This class allows you to get the list of properties on a class. 此类允许您获取类的属性列表。
If you know property name you can call 如果您知道您可以致电的房产名称
Method getter = new PropertyDescriptor(propertyName, beanClass).getReadMethod();
See Also: 也可以看看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.