The problem is that the Unicode replacement is done very early in compilation. Unicode escapes aren't just valid in strings and character literals (as other escape sequences such as \t
are) - they're valid anywhere in code. They're described in a different area of the spec - section 3.3 rather than section 3.10.6; only the latter is about character and string literal escape sequences.
Basically, read section 3 of the spec for more details on lexical structure :)
So your code was actually equivalent to:
public class Test {
public static void main(String argv[]) {
System.out.println("
");
}
}
... which clearly isn't valid code. For carriage return and line feed, basically it's best to use the "\r" and "\n" escape sequences.
Personally I view this handling of Unicode escaping as a flaw in Java, but there's not a lot we can do about it now :(