gpt4 book ai didi

java -\uXXXX、\uuXXXX 和\uuuXXXX 之间的区别

转载 作者:行者123 更新时间:2023-11-29 09:59:05 30 4
gpt4 key购买 nike

下一行来自JLS §3.3 :

If an eligible \ is followed by u , or more than one u , and the last u is not followedby four hexadecimal digits, then a compile-time error occurs.

所以这意味着下面几行的结果是一样的:

System.out.println('\u0065');   // prints "e"
System.out.println('\uu0065'); // prints "e"
System.out.println('\uuu0065'); // prints "e"

\uXXXX 中使用单个 u 与在 \uuXXXX 中使用 uu 本质上是一样的。我的问题是,为什么我们需要这种设计?

最佳答案

原因稍后在引用的部分中说明:

The Java programming language specifies a standard way of transforming a program written in Unicode into ASCII that changes a program into a form that can be processed by ASCII-based tools. The transformation involves converting any Unicode escapes in the source text of the program to ASCII by adding an extra u - for example, \uxxxx becomes \uuxxxx - while simultaneously converting non-ASCII characters in the source text to Unicode escapes containing a single u each.

这意味着它使到 ASCII 的转换完全可逆,因为您知道哪些转义序列最初在代码中,哪些是通过转换添加的。

关于java -\uXXXX、\uuXXXX 和\uuuXXXX 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48321664/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com