首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

施用DynamicProxy和Reflect记录Object的修改历史

2012-10-27 
使用DynamicProxy和Reflect记录Object的修改历史可以用于增量的序列化对象,但是通过记录历史会有冗余,更好

使用DynamicProxy和Reflect记录Object的修改历史
可以用于增量的序列化对象,但是通过记录历史会有冗余,更好的方法是对比Object或者Class字节码。




package com.alzhang.proxy;import java.lang.reflect.Proxy;public class ProxyTest {public static void consumer(Interface iface){iface.doSomething();iface.somethingElse("banaba");}/** * @param args * @throws Exception  */public static void main(String[] args) throws Exception {RealObject real = new RealObject();Interface proxy = (Interface) Proxy.newProxyInstance(Interface.class.getClassLoader(), new Class[]{Interface.class}, new DynamicProxyHandler(real));consumer(proxy);RealObject real2 = new RealObject();real2.stack();real2.history = real.history;real2.invoke();real2.stack();}}


热点排行