Why does Javac reject text blocks ending with four or more " ?

Jayaprakash Artanareeswaran jay.a at outlook.in
Thu Jul 30 05:05:45 UTC 2020


Hello,

The following code is rejected by Javac in JDK 15, although JEP 378 doesn't say anything about it.

    static final String TEXT_BLOCK = """
              1
            """"; // Notice the four quotes here?

In fact, the JEP says this:

"The use of the escape sequences \" and \n is permitted in a text block, but not necessary or recommended. However, representing the sequence """ in a text block requires the escaping of at least one " character, to avoid mimicking the closing delimiter."

So, I would imagine it's perfectly okay for up to two consequent quotes to be used anywhere in a text block.

If this is indeed backed by the spec, can the experts please point me to the relevant section?
Hopefully, I am asking this in the right mailing list.

Thanks,
Jay



More information about the amber-dev mailing list