Java注釋代碼執(zhí)行方法解析
直接上代碼:
@Testpublic void testUnicode() { String a = 'Hello'; // u000d a='world'; System.out.println(a); // u000a a='hello world!'; System.out.println(a);}
猜一猜,最后會(huì)輸出什么?
worldhello world!
是的,沒(méi)看錯(cuò),那二行看似“注釋掉的代碼”,被執(zhí)行了!
原因:java編譯器會(huì)處理unicode字符,u000d以及u000a 正好對(duì)應(yīng)“r”回車(chē)、“n”換行,經(jīng)過(guò)編譯器處理后,等效于下面的代碼:
@Testpublic void testUnicode() { String a = 'Hello'; // a='world'; System.out.println(a); // a='hello world!'; System.out.println(a);}
個(gè)人建議:正式項(xiàng)目中,嚴(yán)禁在注釋中使用這一類(lèi)unicode字符,否則如果利用這個(gè)特性干點(diǎn)壞事,埋個(gè)坑,基本上很難發(fā)現(xiàn)!
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. .NET中l(wèi)ambda表達(dá)式合并問(wèn)題及解決方法2. JSP數(shù)據(jù)交互實(shí)現(xiàn)過(guò)程解析3. 淺談python出錯(cuò)時(shí)traceback的解讀4. 利用promise及參數(shù)解構(gòu)封裝ajax請(qǐng)求的方法5. Python importlib動(dòng)態(tài)導(dǎo)入模塊實(shí)現(xiàn)代碼6. python matplotlib:plt.scatter() 大小和顏色參數(shù)詳解7. windows服務(wù)器使用IIS時(shí)thinkphp搜索中文無(wú)效問(wèn)題8. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向9. 在Android中使用WebSocket實(shí)現(xiàn)消息通信的方法詳解10. Nginx+php配置文件及原理解析
