使用反射回调时出现了异常,这里做一下记录

Method method = instance.getClass().getMethod(setter, filedClazz);
method.invoke(instance, value);
java.lang.IllegalArgumentException: java.lang.ClassCastException@399fa127
    at sun.reflect.GeneratedMethodAccessor289.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

可以看到这个异常是类型不匹配导致的

1、核对一下参数和类型能否对应上

2、int和Integer是两个类型,需要将int的数字包装成Integer处理

 

相关文章:

  • 2021-04-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-01
  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
相关资源
相似解决方案