问题:
The following code produces the output "Hello World!" 以下代码生成输出“Hello World!” (no really, try it). (不,真的,试试吧)。
public static void main(String... args) {
// The comment below is not a typo.
// \u000d System.out.println("Hello World!");
}
The reason for this is that the Java compiler parses the Unicode character \
as a new line and gets transformed into: 原因是Java编译器将Unicode字符\
解析为新行并转换为:
public static void main(String... args) {
// The comment below is not a typo.
//
System.out.println("Hello World!");
}
Thus resulting into a comment being "executed". 从而导致评论被“执行”。
Since this can be used to "hide" malicious code or whatever an evil programmer can conceive, why is it allowed in comments ? 由于这可以用来“隐藏”恶意代码或恶意程序员可以设想的任何东西, 为什么在评论中允许它 ?
Why is this allowed by the Java specification? 为什么Java规范允许这样做?
解决方案:
参考一: https://stackoom.com/question/24vd5/为什么在允许某些Unicode字符的注释中执行Java代码参考二: https://oldbug.net/q/24vd5/Why-is-executing-Java-code-in-comments-with-certain-Unicode-characters-allowed
来源:oschina
链接:https://my.oschina.net/u/3797416/blog/4306726