RFR: Multi-line String Literal (Preview) JEP [EG Draft]

John Rose john.r.rose at oracle.com
Wed May 15 17:35:08 UTC 2019

1/4. FTR, an escape <\ LT> could clean that up
a bit more, if the goal is to get the
interpolation cruft on a separate line:

String code = """
             public void print(\
             """ + type + """
              o) {

2/4. Dan, I'm having trouble seeing your
idea of "prefix" in this example.  Is it that
`String code = ` has the same number of
chars as there are spaces before `public`
(start of the first payload line)? This is hard
to read, I'm afraid.

3/4. Dan, isn't it true that programmers can
use this idiom under the existing proposal,
without appealing to your "prefix" rule?
All they do is (a) keep the close-quotes
(in a single ""+x+"" expression) aligned,
and also (b) don't exdent before the close

4/4. I guess you are proposing two adjustments, the
"prefix" rule and the "no exdent rule".  The "prefix"
rule allows open-quote to set indentation, by counting
arbitrary characters before the open-quote as setting
a target column.  The "no exdent rule" disallows payload
chars in columns before the target column, as set by
the close-quote.  If I'm reading that right, I'm much
happier with the "no exdent rule" than the "prefix" rule.

— John

P.S. In one example you say something about a missing
newline before a close-quote.  Those can always be
introduced explicitly by <\ n>.  One reason I like <\ LT>
is that it pairs very well with <\ n>:  You can put in <\ LT>
to control a line break, and then if you really want a payload
LT also, you add <\ n> either before or after the <\ LT>.

On May 15, 2019, at 10:17 AM, Dan Smith <daniel.smith at oracle.com> wrote:
> ~~~
> String code = """
>              public void print(""" +
>              type +
>              """
>               o) {
>                  System.out.println(Objects.toString(o));
>              }
>              """;
> ~~~

More information about the amber-spec-experts mailing list