Java how to call method by reflection with primitive types as arguments

前端 未结 2 953
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 12:53

I have the following two methods in a class:

public void Test(int i){
    System.out.println(\"1\");
}
public void Test(Integer i){
    System.out.println(\"         


        
2条回答
  •  情话喂你
    2020-12-05 13:12

    Strange but true:

    this.getClass().getMethod("Test",int.class).invoke(this, 10);
    

提交回复
热议问题