线程底部实现原理 静态代理 小例子婚庆公司
作者:互联网
实现接口类方法HappyMarry
我结婚专注自己的事(结婚)
婚庆公司做布置
最后主线程调用
整体代码
public class StaticProxy { public static void main(String[] args) { WeddingCompany cost = new WeddingCompany(new Myself()); cost.HappyMarry();//以上两行可写成new WeddingCompany(new Myself())。HappyMarry } } interface Marry { void HappyMarry(); } //真实角色,我去结婚 class Myself implements Marry { @Override public void HappyMarry() { System.out.println("我要结婚了"); } } //代理角色,帮助我结婚 class WeddingCompany implements Marry { private Marry target; public WeddingCompany(Marry target) { this.target = target; } @Override public void HappyMarry() { before(); this.target.HappyMarry(); after(); } private void before() { System.out.println("结婚之前布置现场"); } private void after() { System.out.println("结婚之后收尾款"); } }
标签:target,静态,婚庆,public,WeddingCompany,线程,HappyMarry,Marry,void 来源: https://blog.csdn.net/weixin_46044449/article/details/120578589