@Deprecated使用技巧
生活随笔
收集整理的這篇文章主要介紹了
@Deprecated使用技巧
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本文轉自?http://www.cnblogs.com/hzhuxin/p/4645070.html
? 我們在做項目時,前期寫的類中的一些代碼可能由于需求變化的原因需要重寫,有時重寫時方法的傳參和返回值也會發生變化,這樣往往導致調用的代碼也跟著出錯,我們看下spring的代碼是如何處理這樣的事,先看下面兩段代碼,上面這段是之前的getHandler方法,現在需要改成第二段代碼,方法的參數cache不要了,而且方法內部的實現肯定也變化了,spring框架的作者先是在之前的方法上加了@Deprecated標志,然后讓舊的方法去調用新的方法,相當于舊方法起了個臨時代理的作用,這樣之前調舊gethandler方法的代碼也不會出問題,而實現已經切換成了新的實現,并且后面寫代碼的人看到了舊方法的@Deprecated標志后,也會避免調用它,而直接選擇去調用新的getHandler方法。
@Deprecatedprotected HandlerExecutionChain getHandler(HttpServletRequest request, boolean cache) throws Exception {return getHandler(request);} protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {for (HandlerMapping hm : this.handlerMappings) {if (logger.isTraceEnabled()) {logger.trace("Testing handler map [" + hm + "] in DispatcherServlet with name '" + getServletName() + "'");}HandlerExecutionChain handler = hm.getHandler(request);if (handler != null) {return handler;}}return null;}?
轉載于:https://www.cnblogs.com/chrischris/p/6514655.html
總結
以上是生活随笔為你收集整理的@Deprecated使用技巧的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 亿纬锂能属于哪个板块
- 下一篇: 启动Tomcat的小细节--MyEcli