笔试题:写一个ArrayList 的动态代理类
public class ProxyTest {
public static void main(String[] args) {
final ArrayList<String> list = new ArrayList<>();
List<String> listProxy=(List<String>) Proxy.newProxyInstance(list.getClass().getClassLoader(), list.getClass().getInterfaces(), new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return method.invoke(list,args);
}
});
listProxy.add("你好") ;
System.out.println(list);
}
}
文章来自www.wityx.com,转载请注明出处!原文地址http://www.wityx.com/post/1314_1_1.html
java面试题交流群:327440556