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

查看:33
本文介绍了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.

因此,注释中的 u000d 被解析为换行符,结束注释并开始实例初始化器.

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天全站免登陆