Java中的unicode换行符(\ u000d) [英] A unicode newline character(\u000d) in Java

查看:1088
本文介绍了Java中的unicode换行符(\ u000d)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们在Java中看到以下代码片段。

Let's see the following code snippet in Java.

public class Main {
    public static void main(String[] args) {
        // new Character(' \u000d System.out.println("Hello");
    }
}






在上面的代码中,虽然 main()中的唯一一行方法被注释掉,它在控制台上显示输出 Hello ,即使看起来这个注释行包含一些语法错误。如果这行没有注释,它根本不起作用,导致编译时错误。


In the above code, although the only line in the main() method is commented out, it displays the output Hello on the console, even though it looks like that this commented line contains some syntax errors. If this line is uncommented, it will not work at all, causing a compile-time error.

为什么在这里输出Hello?

Why does it output "Hello" here?

推荐答案

Java解析源代码中的字符转义码,而不仅仅是字符串。

这允许您使用不带Unicode编码的Unicode标识符。

Java parses character escape codes in source code, not just strings.
This allows you to use Unicode identifiers without a Unicode encoding.

因此,评论中的 \\\ 将被解析为换行符,结束评论并开始实例初始化程序。

Therefore, the \u000d in the comment is parsed as a newline, ending the comment and beginning an instance initializer.

这篇关于Java中的unicode换行符(\ u000d)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆