[英]How to access private field via BeanInfo<I> in java
I know how to access private fields via Class.forName() and Field[]. 我知道如何通过Class.forName()和Field []访问私有字段。 Now I am trying samething via BeanInfo Interface. 现在,我正在通过BeanInfo接口尝试相同的操作。
What I did is below. 我所做的如下。
get Class instance via Class.forName() 通过Class.forName()获取Class实例
BeanInfo info = Introspector.getBeanInfo(Class) - Here, I can see 'org.owls.anno.vo.Target'. BeanInfo info = Introspector.getBeanInfo(Class)-在这里,我可以看到“ org.owls.anno.vo.Target”。
get elements via for syntax. 通过语法获取元素。
for(PropertyDescriptor pd : info.getPropertyDescriptors()){ log.info(pd.getName()); for(PropertyDescriptor pd:info.getPropertyDescriptors()){log.info(pd.getName()); log.info(pd.getDisplayName()); log.info(pd.getDisplayName()); log.info(pd.getPropertyType()); log.info(pd.getPropertyType()); } }
I expected list of Field names(msg, open_msg), but it prints 'class.java.lang.Class'. 我期望列出字段名称(msg,open_msg),但它会打印“ class.java.lang.Class”。
The Target Class is here 目标类别在这里
package org.owls.anno.vo;
import org.owls.anno.SimpleAnnotation;
@SimpleAnnotation("Add missing attributes")
public class Target {
private String msg;
public String open_msg;
public Target(String msg) {
super();
this.msg = msg;
}
@Override
public String toString() {
return "Target [msg=" + msg + "]";
}
};
Thanks for Answer :D 感谢您的回答:D
您的课程不是bean:没有访问器(getter和/或setter)... getClass()
除外!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.