【Java开源代码栏目提醒】:网学会员为需要Java开源代码的朋友们搜集整理了VectorProxy.java相关资料,希望对各位网友有所帮助!
package com.javapatterns.proxy.reflect;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.lang.reflect.Method;
import java.util.Vector;
import java.util.List;
public class VectorProxy implements InvocationHandler
{
private Object proxyobj;
/** @link dependency */
/*#Proxy lnkProxy;*/
public VectorProxy(Object obj)
{
proxyobj = obj;
}
public static Object factory(Object obj)
{
Class cls = obj.getClass();
return Proxy.newProxyInstance( cls.getClassLoader(),
cls.getInterfaces(),
new VectorProxy(obj) );
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
System.out.println("before calling " + method);
if (args != null)
{
for (int i=0; i<args.length; i++)
{
System.out.println(args[i] + "");
}
}
Object o = method.invoke(proxyobj, args);
System.out.println("after calling " + method);
return o;
}
public static void main(String[] args)
{
List v = null;
v = (List) factory(new Vector(10));
v.add("New");
v.add("York");
}
}
上一篇:
VectorFindDemo.java
下一篇:
关于大学英语教学