Nick Silicon
Nick Silicon

Reputation: 71

Behaviors of unicode escape sequence in comments

According to "Core Java Vol. I" by Cay Horstmann:

quote

So, the below code should not work:

class Test
{
    public static void main(String[] arg2) 
    {
        // \u00A0 is a new line  
        char alpha = 'a';
        System.out.println("abc" + alpha);
    }
}

But it works. Why?

Upvotes: 1

Views: 77

Answers (1)

JonK
JonK

Reputation: 2108

The code works because the character \u00A0 is a non-breaking space and not a newline character.

Most likely what has happened is that the author has made a typo and actually meant to type \u000A, which is a line feed character and does indeed break as expected.

Upvotes: 4

Related Questions