`
yanshaozhi
  • 浏览: 102858 次
  • 性别: Icon_minigender_1
  • 来自: 东营
社区版块
存档分类
最新评论

java动态代理

阅读更多
被代理的对象  厂家
代理对象       商家
public interface IIBM {
	public void sell();
}

public class IBM implements IIBM{

	public void sell() {
		System.out.println("sell  a goods !");
	}
}

public static void main(String[] args) {
		IIBM i =(IIBM) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
				new Class[]{IIBM.class}, new InvocationHandler() {
					public Object invoke(Object proxy, Method method,
							Object[] args) throws Throwable {
						IIBM i = new IBM();
						System.out.println("sss .");
						i.sell();
						return i;
					}
				});
		i.sell();
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics