Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用java反射设置Field的值.传入的参数是Class对象.报错 #3

Open
deanjo opened this issue May 26, 2018 · 0 comments
Open

Comments

@deanjo
Copy link

deanjo commented May 26, 2018

大神还好,Resolver类中使用反射设置字段的值的时候代码如下:
field.set(Class clazz,Field field,Object value;传入的是Class对象.在运行的是报错.传入参数异常
这里是不是应该是field.set(Object obj,Field field,Object value).
在jdk的反射源码这里报错UnsafeFieldAccessorImpl
protected void ensureObj(Object o) {
// NOTE: will throw NullPointerException, as specified, if o is null
if (!field.getDeclaringClass().isAssignableFrom(o.getClass())) {
throwSetIllegalArgumentException(o);
}
}
我理解的是.因为传入的Class对象.如果一个类有new出了多个对象.只传入Class 反射不知道到底修改谁的
所以需要传入具体修改那个对象.
请大神指教 ~~~`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant