- import java.lang.reflect.Method;
- import java.util.ArrayList;
- public class DemoTest
- {
- public static void main(String[] args) throws Exception
- {
- ArrayList<Integer> list = new ArrayList<Integer>();
- list.add(231);//开始只能+整形
- System.out.println(list);
-
-
- Method addclass = list.getClass().getMethod("add", Object.class);
- addclass.invoke(list, "哈哈");
-
- System.out.println(list);
- }
复制代码
希望能帮主你 |