- import java.lang.reflect.InvocationHandler;
- import java.lang.reflect.Method;
- import java.lang.reflect.Proxy;
- import java.util.ArrayList;
- import java.util.Collection;
- public class c2 {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Student proxy1=(Student)Proxy.newProxyInstance(
- Student.class.getClassLoader(),
- new Class[]{Student.class},
-
- new InvocationHandler() {
-
- @Override
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
- // TODO Auto-generated method stub
- //Object obj=method.invoke(target, args);
- return null;
- }
- });
- proxy1.setAge(1);
- }
- }
复制代码 错误信息显示:
Exception in thread "main" java.lang.IllegalArgumentException: Exercise.Student is not an interface
at java.lang.reflect.Proxy.getProxyClass(Proxy.java:362)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
at Exercise.c2.main(c2.java:16)
难道代理是对接口而言的? |
|