阅读背景:

method.invoke上的参数数量错误

来源:互联网 

I currently have this code:

我目前有这个代码:

public class Pants {
    public static void main(String[] args) {
        Pants pants = new Pants();
        pants.eat(10, 10.3, "Nice.");

        Object[] params = {(long)10, 10.3, "Nice."};
        Method eatMethod = pants.getClass().getMethods()[0];
        try
        {
            eatMethod.invoke(pants, params);
        } catch (IllegalAccessException | InvocationTargetException e)
        {
            e.printStackTrace();
        }
    }

    public void eat(long amount, double size, String name) {
        System.out.println("You ate");
    }
}
publi



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: