`

根据对象和方法名和参数来调用该方法

阅读更多
public class ReflectTest {

    public static void main(String[] args) throws Exception {
        ReflectTest reflectTest=new ReflectTest();
        Method method=reflectTest.getClass().getMethod("say", Map.class);
        
        Map<String,Object> params=new HashMap<String, Object>();
        params.put("name", "zhangsan");
        method.invoke(reflectTest, params);
    }
    
    public void say(Map<String,Object> params){
        System.out.println(params);
    }
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics