Java注释中的\ u导致错误信息,为什么?

编程入门 行业动态 更新时间:2024-10-23 17:37:22
本文介绍了Java注释中的\ u导致错误信息,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 // \u represent unicode sequence char c = '\u0045'; System.out.println(c);

代码只是这么多,eclipse显示以下错误消息

Code is only this much and eclipse is showing following error message

"Exception in thread "main" java.lang.Error: Unresolved compilation problem: Invalid unicode

现在,当我从评论中删除 \u 时它工作正常,有什么问题? code> \ u 评论?这是一个错误还是有一些关系,因为认为Java应该保留评论。

Now when I remove \u from comment it is working fine, what is the problem with \u in comment? IS this a bug or there is some relation, as far as think Java should leave the comments as it is.

推荐答案

编译器会首先读取你的整个源代码(稍后会忽略注释),但是他无法识别\ u,因为它不是有效的unicode-character。

The compiler will read your entire source code first (the comment will be ignored later), but he can't recognize "\u ", because it is no valid unicode-character.

要修复它,你可以写

// \\u represent unicode sequence (extra backslash for escaping)

// \ u represent unicode sequence (extra whitespace for escaping)

编辑: 这是因为编译器首先将所有内容翻译成unicode。编写这个简单的程序

This is because the compiler translates everything into unicode first. Writing this simple programm

class Ideone { public static void main (String[] args) { // \u000A System.out.println("Hi"); } }

输出嗨,因为 \ u000A 代表换行符。 证明

outputs Hi, because \u000A stands for newline. Proof

更多推荐

Java注释中的\ u导致错误信息,为什么?

本文发布于:2023-11-03 20:17:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555987.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误信息   注释   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!