[英]What's the best way to get Attribute value with Reflection in Java
I know i can get the attribute names, types, and set their values from an Object. 我知道我可以从对象中获取属性名称,类型并设置其值。
I wanna know what's the best way to get their values via reflections. 我想知道通过反思获得价值观的最佳方法是什么。
EDIT: For meaning. 编辑:意义。 Best is like, less code, less memory and faster execution. 最好就是减少代码,减少内存并加快执行速度。
Like: Is it better if I try to invoke the methods to get their values, or if I use something like this: 像:如果我尝试调用方法以获取它们的值,或者如果我使用类似以下的方法,那会更好:
Object obj;
Class cls = obj.getClass();
cls.getField("atribute1").get(obj).toString();
我所知道的最好方法是使用Apache BeanUtils
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.