解析Unicode转义序列带来的问题

Unicode转义序列的解析是发生在代码编译之前,编译器机械的将u样式的代码文本转义,即使是注释以及非正常代码,对此步骤来说也没有区别

导致下面的情况:

 1 public class Test {
 2     public static void main(String[] args) {
 3         System.out.println("u0022+u0022");//""+""=null
 4         //u000a System.out.println("annotation !");//print success!
 5         //
 System.out.println("annotation !");//print success!
 6        
 7     }
 8 }
 9 Output:
10 
11 annotation !

由于机械转义,"u0022+u0022"实际上是""+""即两个空字符串相加,所以打印为空

注释中的u000a被转移成 换行符,所以其后的print代码得以执行

而普通的 转义序列却不会产生问题

原文地址:https://www.cnblogs.com/gjl-blog/p/8572292.html