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!
是的,沒看錯(cuò),那二行看似“注釋掉的代碼”,被執(zhí)行了!
原因:java編譯器會(huì)處理unicode字符,u000d以及u000a 正好對(duì)應(yīng)“r”回車、“n”換行,經(jīng)過編譯器處理后,等效于下面的代碼:
@Testpublic void testUnicode() { String a = 'Hello'; // a='world'; System.out.println(a); // a='hello world!'; System.out.println(a);}
個(gè)人建議:正式項(xiàng)目中,嚴(yán)禁在注釋中使用這一類unicode字符,否則如果利用這個(gè)特性干點(diǎn)壞事,埋個(gè)坑,基本上很難發(fā)現(xiàn)!
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. React+umi+typeScript創(chuàng)建項(xiàng)目的過程2. ASP調(diào)用WebService轉(zhuǎn)化成JSON數(shù)據(jù),附j(luò)son.min.asp3. php測(cè)試程序運(yùn)行速度和頁面執(zhí)行速度的代碼4. php網(wǎng)絡(luò)安全中命令執(zhí)行漏洞的產(chǎn)生及本質(zhì)探究5. ASP.NET Core 5.0中的Host.CreateDefaultBuilder執(zhí)行過程解析6. 無線標(biāo)記語言(WML)基礎(chǔ)之WMLScript 基礎(chǔ)第1/2頁7. Warning: require(): open_basedir restriction in effect,目錄配置open_basedir報(bào)錯(cuò)問題分析8. ASP中常用的22個(gè)FSO文件操作函數(shù)整理9. SharePoint Server 2019新特性介紹10. 三個(gè)不常見的 HTML5 實(shí)用新特性簡(jiǎn)介
