CharLemAznable / blog

When I was young, I used to think that money was the most important thing in life, now that I am old, I know it is.
MIT License
4 stars 0 forks source link

空方法编译报错?! #23

Open CharLemAznable opened 3 years ago

CharLemAznable commented 3 years ago

这是一个有趣的事情: Java的注释会影响代码的编译

这是一种特殊的情况: 编译器会解析Unicode字符,可能导致代码会在编译时报错

public class CompileError {
    public static void main(String[] args) {
        // \u000d 运行编译报错
    }
}
CompileError.java:3: error: not a statement
       // \u000d 运行编译报错
                 ^
CompileError.java:3: error: ';' expected
       // \u000d 运行编译报错
                       ^
2 errors
Error: Could not find or load main class CompileError
Caused by: java.lang.ClassNotFoundException: CompileError

参考来源: SaminZou/study-prj: Q3/AnnotationProblem.java