How unicode characters are read in java comments

class Why
{
    public static void main(String[]s)
    {
        String st2="A";
        System.out.println(st2);
        // String st4="MN3444\u000ar4t4";
        System.out.println(st4);

    }
}

please compile the above code, I get an error message in the comment line.

I cannot understand this compiler behavior, and what does this error mean?

+4
source share
2 answers

Before compilation, each Unicode character is replaced by its value, and since it \u000arepresents a new line code

// String st4="MN3444\u000ar4t4";

matches this code (note that the text after \u000awill be moved to a new line, which means that it will no longer be part of the comment)

// String st4="MN3444
r4t4";

You can test it with

//\u000a;System.out.println("hello comment");

which is equal

//
System.out.println("hello comment");

and will give you the result: hello comment

+5
source

ASCII \u000a, , . , ASCII escape . , :

// String st4="MN3444
r4t4";

: " ".

, , :

/* String st4 = "MN3444\u000ar4t4"; */

:

   /* String st4="MN3444
r4t4"; */

.


: JLS §3.2.

Unicode , :

Unicode (§3.3) Unicode . Unicode \uxxxx, xxxx , UTF-16, xxxx. , , ASCII.


, , :)

\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u0022\u0054\u0068\u0069\u0073\u0020\u0069\u0073\u0020\u0063\u006f\u006f\u006c\u0021\u0022\u0029\u003b
+3

All Articles