I was playing around with Java Unicode Escapes and accidentally found the following interesting oddities. Here is the code that I wrote:
static void main(String... args) {
/*
* \u0027 - single quote
*/
char e = \u0027\n\u0027;
char f = '\'';
System.out.println(e == f);
//output: true
}
Looking at the compiled code, the Java compiler translated them into the same character literal.
char e = '\'';
char f = '\'';
By what conversion rules e
has become a '
instead of a linefeed \n
?
BTW I am using Oracle JDK 19 on Windows 11.
EDIT: It seems like the issue is related to Java compilers failing to work according to the Java Language Specification.
EDIT: It seems like the issue happens when Oracle JDK 19 runs in JLS 18 mode. (I am not sure how to say this properly)