Why can some ASCII characters not be expressed in the form '\uXXXX' in Java source code?

前端 未结 5 1608
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 12:19

I stumbled over this (again) today:

class Test {
    char ok = \'\\n\';
    char okAsWell = \'\\u000B\';
    char error = \'\\u000A\';
}

It

5条回答
  •  情歌与酒
    2020-12-13 13:07

    I think the reason is that \uXXXX sequences are expanded when the code is being parsed, see JLS §3.2. Lexical Translations.

提交回复
热议问题