简写的代码,成功输出
class ReflectTest
{
public static void main(String args[]) throws Exception
{
ArrayList<Integer> list = new ArrayList<Integer>() ;
String str = "eeeeeeeee" ;
list.getClass().getMethod("add",Object.class).invoke(list,str) ;
System.out.println(list.get(0)) ;
}
} |