第一张图的 反射对象是
这说明 你 这个clazz 对象就不一样吧, 你看看 clazz是啥
//通过反射生成:AccountServiceImpl对象 public IAccountService getInstence(){ AccountServiceImpl accountService = null; try{ accountService = AccountServiceImpl.class.getDeclaredConstructor(String.class,Integer.class).newInstance("heihei",12); }catch (Exception ex ){ ex.printStackTrace(); } return accountService; }
注:getDeclaredConstructor()方法会根据他的参数对该类的构造函数进行搜索并返回对应的构造函数,没有参数就返回该类的无参构造函数,然后再通过newInstance进行实例化。