public class insertStrToArray {
public static void main(String[] args) throws Exception {
ArrayList<Integer> list = new ArrayList<Integer>(); (泛型是integer)
Method methodAddString = list.getClass().getMethod("add", Object.class);
methodAddString.invoke(list, "abc"); (不过这里利用反射,加进去一个string类型。所以骗过了编译)
System.out.println(list);
}
} |