java动态代理

痞子三分冷 提交于 2019-11-29 20:06:47

代理对象       商家
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();
	}

转载于:https://my.oschina.net/u/2296689/blog/545753

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!