Use of the "Java doubts" Unicode escape character (cont.)

Source: Internet
Author: User


The code is as follows:

public class Example016 {public static void main (string[] args) {char c = 0x000a;/** * \u000a Note 1 *///\u000a comment 2system.ou T.println ("c =" + C); System.out.println ("A New Line");}


Results:

At compile time, note 2 error occurred, resulting in incorrect compilation.

Results Analysis:

The Java compiler not only converts Unicode escape characters into the characters they represent before parsing the program into symbols, but it does this before discarding comments and spaces. that is, when the compiler compiles the above code, it first converts the \u000a into a newline. For note 1, the comment is not affected after wrapping, and for note 2, the "Note 2" character is changed to the next line as part of the formal code, which naturally does not compile correctly.

From the use of Unicode escape characters two blog posts, we can conclude thatUnicode escape characters are absolutely confusing. Do not use Unicode escape characters unless they are indeed required. They are seldom required.



(Note: This "Java doubts" series, are bloggers read "Java doubts" original book, the original book on the explanation and example part of the adaptation, and then write a blog post. All examples are tested in person and shared on GitHub. Use these examples to motivate yourself and benefit others. At the same time, all posts in this series will be posted in the blogger's personal public number (search for "Love Ape" or "ape_it") for easy reading. If there is any infringement of the original rights of the author's content, please inform the blogger in time, in order to promptly delete, if the reader has objection to the content of the text or questions, welcome to the Blog or public messages and other ways to discuss together. )

Source code Address: Https://github.com/rocwinger/java-disabuse




This article from "Winger" blog, declined reprint!

Use of the "Java doubts" Unicode escape character (cont.)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.