Relaxing constraint for text blocks to start on new line?
Remi Forax
forax at univ-mlv.fr
Wed Nov 30 11:09:38 UTC 2022
Sorry to not answer sooner,
the reason to not allow anything after the first """ is that we may add modifiers after the """ in the future,
by example, if we do not want the character '\' to be escaped, in the future you may able to write
String text = """ no-escape
some text with a \n
""";
regards,
Rémi
> From: "Vikram Bakshi" <vab2048 at gmail.com>
> To: "amber-dev" <amber-dev at openjdk.java.net>
> Sent: Tuesday, November 22, 2022 11:42:07 AM
> Subject: Relaxing constraint for text blocks to start on new line?
> Hello,
> Text blocks are a great feature of the Java language. On the JEP page one of the
> listed goals of text blocks is to:
> *
> * Enhance the readability of strings in Java programs that denote code written
> in non-Java languages.
> Currently when attempting to use text blocks for short strings which can fit on
> one line for a non-Java language (e.g. JSON) we still need to start the string
> on another line.
> For example:
> ```java
> var json = """
> { "color": "red", "value": "#f00" } """
> ```
> It would be a lot nicer to have the ability to use the triple quote to define
> strings like this on one line:
> ```java
> var json = """{ "color": "red", "value": "#f00" } """
> ```
> Currently that is not possible and using a normal quote for strings, ", requires
> us to escape all of the subsequent quotes on the same line - which is a real
> pain.
> Obviously we can just continue to start on the next line to avoid the issue -
> but is it possible to consider an extension to text blocks which allow for this
> use case (short one line strings)?
> Regards,
> Vikram
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20221130/1e770f2b/attachment.htm>
More information about the amber-dev
mailing list