调用 ```java Method declaredMethod = bean.getClass().getDeclaredMethod( "set" + propertyValue.getName().substring(0, 1).toUpperCase() + propertyValue.getName().substring(1), value.getClass()); ``` 抛出异常 ``` java.lang.NoSuchMethodException: us.codecraft.tinyioc.HelloWorldServiceImpl.setOutputService(us.codecraft.tinyioc.OutputServiceImpl) ``` 但是`HelloWorldServiceImpl`有这个`set`方法 ```java package us.codecraft.tinyioc; /** * @author yihua.huang@dianping.com */ public class HelloWorldServiceImpl implements HelloWorldService { private String text; private OutputService outputService; @Override public void helloWorld() { outputService.output(text); } public void setText(String text) { this.text = text; } public void setOutputService(OutputService outputService) { this.outputService = outputService; } public OutputService getOutputService() { return outputService; } } ```
Activity
castleKing1997 commentedon Oct 19, 2021
定位到
java.lang.Class.arrayContentsEq,这个方法的作用是:在查找方法时,判断参数列表是否相同
OutputService和OutputServiceImpl在判断时是不相等的,所以无法正确定位到set方法
castleKing1997 commentedon Oct 19, 2021
考虑到这里是反射获取set方法,set方法一般不重名
所以可以考虑只通过方法名反射获取set方法 #35