Nick Silicon Nick Silicon - 2 months ago 22
Java Question

Behaviors of unicode escape sequence in comments



class Test
{
public static void main(String[] arg2)
{
// \u00A0 is a new line

char alpha = 'a';

System.out.println("abc" + alpha);


}
}


According to Core Java Vol. I by Cay Horstmann, above code should not work. But it's working. Why is it so?

Answer

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.

Comments