- public static void main(String[] args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
- // TODO Auto-generated method stub
- ArrayList<String> c1=new ArrayList<String>();
- //c1.add(1);
- Method method=c1.getClass().getMethod("add",Object.class);
- method.invoke(c1, Integer.valueOf(10));
- System.out.println(c1.get(0));
-
-
-
- ArrayList<Integer> c2=new ArrayList<Integer>();
- Method method1=c2.getClass().getMethod("add",Object.class);
- method1.invoke(c2, "ac");
- System.out.println(c2.get(0));
- }
- }
复制代码 为什么integer不可以转成String ,但是String却可以转换成integer类型的呢? |