how to pass multiple parameters to a method in java reflections

前端 未结 4 1568
庸人自扰
庸人自扰 2020-12-30 15:15

Hi i am using reflections to achieve something. I have been given class name, method name of that class and parameter values that needs to be passed to that method in a file

4条回答
  •  心在旅途
    2020-12-30 15:27

    For two int parameters the example is as below, similarly other datatype parameters can also be called

    Method method=new Test1().getClass().getMethod(x, new Class[] {int.class,int.class});
    

    We can call a method that needs 3 arguments int,int,string as below :

    Method method=new Test1().getClass().getMethod(x, new Class[] {int.class,int.class, String.class});
    

提交回复
热议问题