在线不卡日本ⅴ一区v二区_精品一区二区中文字幕_天堂v在线视频_亚洲五月天婷婷中文网站

  • <menu id="lky3g"></menu>
  • <style id="lky3g"></style>
    <pre id="lky3g"><tt id="lky3g"></tt></pre>

    動態(tài)代理設(shè)計模式

    public interface SleepService { void sleep();}@Slf4jpublic class SleepServiceImpl implements SleepService { @Override public void sleep() { log.info(“睡覺了”); }}import lombok.extern.slf4j.Slf4j;import java.lang.reflect.InvocationHandler;import java.lang.reflect.Method;@Slf4jpublic class SleepServiceProxy implements InvocationHandler { private SleepServiceImpl sleepServiceImpl; public SleepServiceProxy() { } public SleepServiceProxy(SleepServiceImpl sleepServiceImpl) { this.sleepServiceImpl = sleepServiceImpl; } private SleepService sleepService = new SleepServiceImpl(); @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { log.info(“睡覺前關(guān)燈”); Object o = method.invoke(sleepServiceImpl,args); return o; }}import java.lang.reflect.Proxy;public class MainTest { public static void main(String[] args) { SleepService sleepService = (SleepService) Proxy.newProxyInstance(SleepServiceImpl.class.getClassLoader(), new Class[]{SleepService.class}, new SleepServiceProxy(new SleepServiceImpl())); sleepService.sleep(); }}

    鄭重聲明:本文內(nèi)容及圖片均整理自互聯(lián)網(wǎng),不代表本站立場,版權(quán)歸原作者所有,如有侵權(quán)請聯(lián)系管理員(admin#wlmqw.com)刪除。
    上一篇 2022年6月14日 09:12
    下一篇 2022年6月14日 09:12

    相關(guān)推薦

    聯(lián)系我們

    聯(lián)系郵箱:admin#wlmqw.com
    工作時間:周一至周五,10:30-18:30,節(jié)假日休息