I read the following phrase in the Java language specification.
It is a compile-time error for the character following the SingleCharacter or EscapeSequence to be other than a '.'
I am not able to understand what is the meaning of above line. Could someone please explain it with example.
What is says is basically: A compile time error will be generated for every character different than a
', that comes after the "character" itself. Where the "character" is the content in the form of a character (like:a,0,\u0093) or an escape sequence (like:\\,\b,\n).So, this will be wrong:
'aa', because the secondais not a single quote (').'\\a', because the second character (thea) is not a single quote.'a, because the character which comes after the "content" is not a quote (but probably a newline or a space).Side note: This won't work either:
char c = '\u0027';. Because that is the code point for a single quote, so it gets translated into:char c = ''';.