开发者

Access private object using java reflection api

开发者 https://www.devze.com 2023-02-15 13:38 出处:网络
Can I 开发者_如何学JAVAaccess and get the value of object using java reflection ther is method to get --getLong,getInt ,but I couldn\'t find getObject()Are you looking for simply Field.get(Object obj

Can I 开发者_如何学JAVAaccess and get the value of object using java reflection

ther is method to get --getLong,getInt ,but I couldn't find getObject()


Are you looking for simply Field.get(Object obj)?


Class aClass = MyObject.class
Field field = aClass.getField("someField");

The example above will return the Field instance corresponding to the field someField
as declared in the MyObject below:

public class MyObject{
public String someField = null;
}

If no field exists with the name given as parameter to the getField() method, a
NoSuchFieldException is thrown.

0

精彩评论

暂无评论...
验证码 换一张
取 消