samedi 30 mai 2015

Exception when invoke reflection Class.getMethod

I have below code which invokes a method using reflection. But i am getting,

java.lang.IllegalArgumentException: wrong number of arguments

exception at Method.invoke. What is the reason?

public class B {
    public static void main(String[] args) {
        A a = new A();
        Method m;
        try {
            m = a.getClass().getMethod("m3",Integer.class);
            m.invoke(a);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

public class A {    
    public void m3(Integer x){
        System.out.println("ssss");
    }
}





Aucun commentaire:

Enregistrer un commentaire