2020-08-02通过反射向Integer数组中添加字符串
作者:
智障猿 | 来源:发表于
2020-08-12 16:10 被阅读0次public class Demo {
public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
ArrayList<Integer> arrayList = new ArrayList<>();
arrayList.add(15);
Class<? extends ArrayList> aClass = arrayList.getClass();
Method add = aClass.getMethod("add", Object.class);
add.invoke(arrayList,"hello");
add.invoke(arrayList,"world");
System.out.println(arrayList);
}
}
本文标题:2020-08-02通过反射向Integer数组中添加字符串
本文链接:https://www.haomeiwen.com/subject/eraprktx.html
网友评论