ArrayList list = new ArrayList();在这个泛型为 Integer 的 ArrayList 中存放一个 String 类型的对象。,arraylistinteger
分享于 点击 20638 次 点评:81
ArrayList list = new ArrayList();在这个泛型为 Integer 的 ArrayList 中存放一个 String 类型的对象。,arraylistinteger
package com.heima.test;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
public class Test2 {
/**
ArrayList<Integer> list = new ArrayList<Integer>();在这个泛型为 Integer 的 ArrayList
中存放一个 String 类型的对象。
* @param args
* @throws SecurityException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalArgumentException
* @throws IllegalAccessException
*/
public static void main(String[] args) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
ArrayList<Integer> list = new ArrayList<Integer>();
Class clazz = ArrayList.class;
Method me = clazz.getMethod("add", Object.class);
me.invoke(list, "heima");
System.out.println(list);
}
}
相关文章
- 暂无相关文章
用户点评