在使用反射执行一个方法时常遇到object is not an instance of declaring class的异常,如下代码:
第34行会报object is not an instance of declaring class错 对象不是声明类的一个实例。解决办法如下:
第一种:反射执行的方法 getPrimaryKey() 改成静态的
第二种:在执行方法前先实例化类。m.invoke(mothed,null)改为m.invoke(c.newInstance(),null)或者m.invoke(new PrimaryKeyUtils(),null)