import java.lang.reflect.Method;
public class demoTest {
public static void main(String[] args) throws Exception {
Class<?> c=Class.forName("java.util.Arrays");
//Object a=c.newInstance();
Method h= c.getMethod("asList", Object[].class);
System.out.print(h.getTypeParameters()[0].getName().toString());
//Object a []={"aa","dd"};
h.setAccessible(true);
Object g=h.invoke(c, "a");
g= h.getReturnType().cast(g);
System.out.println(g.toString());
}
}
Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at demoTest.main(demoTest.java:14)
问题出在那?
|
|