![](/img/trans.png)
[英]Why getDeclaredMethod with Class as second param throws NoSuchMethodException?
[英]ArrayList<Integer> getDeclaredMethod("add", Integer.class) throws NoSuchMethodException
ArrayList<Integer> intList = new ArrayList<>(); intList.getClass().getDeclaredMethod("add", Integer.class); // throws NoSuchMethodException //where as intList.getClass().getDeclaredMethod("add", Object.class); // is just fine.
当然,在这种情况下,我希望第一个工作。 或者至少弄清楚如何从泛型类型参数获取方法。
当循环声明的方法时, add
方法明确表示 Object:
public boolean java.util.ArrayList.add(java.lang.Object)
我的猜测是我错过了一些简单的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.