Nick Silicon Nick Silicon - 1 month ago 6x
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?


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.