- Collection Proxy1 =(Collection)con.newInstance(new MyInvocationHandler1());//只能调用 带参构造函数创建实例对象,参数是一个InvocationHandler对象,他是一个实现接口类的对象
-
- Collection Proxy2 =(Collection)con.newInstance(new InvocationHandler(){
- @Override
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
- // TODO Auto-generated method stub
- return null;
- }}) ;
-
- Collection Proxy3=(Collection)Proxy.newProxyInstance(Collection.class.getClassLoader(), new Class[] {Collection.class},new InvocationHandler() {
-
- @Override
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
- // TODO Auto-generated method stub
- ArrayList targect=new ArrayList();
- long startTime=System.currentTimeMillis();
- Object ss=method.invoke(targect, args);
- long endTime1=System.currentTimeMillis();
- System.out.println(startTime-endTime1);
- return ss;
- }
- });
复制代码
是这么?代理看的乱七八糟的弄不明白 |