问答详情
源自:5-1 Java 方法反射的基本操作

这里错误是什么?为什么不能转换?

package com.imooc;


import java.lang.reflect.Method;


public class Example {


public static void main(String[] args) {

A a1 = new A();

Class c = a1.getClass();

try {

//Method m = c.getMethod("print",new Class[]{int.class,int.class});

Method m = c.getMethod("print",new Class[]{int.class,int.class});

Object object = m.invoke(a1,10,20);

} catch (Exception e) {

e.printStackTrace();

}

}


}


class A{

public void print(int a,int b){

System.out.println(a+b);

}

private void print(String a,String b){

System.out.println(a.toUpperCase()+","+b.toLowerCase());

}

}


提问者:RSF 2018-07-06 16:24

个回答

  • qq_仰望星空_96
    2018-09-29 12:25:27

    没ctrl+s?


  • fufupower
    2018-07-08 00:40:29

    运行没毛病啊