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

Dan Smith daniel.smith at oracle.com
Wed May 15 18:25:14 UTC 2019



> On May 15, 2019, at 12:11 PM, Alex Buckley <alex.buckley at oracle.com> wrote:
> 
> On 5/15/2019 10:17 AM, Dan Smith wrote:
>> I think this:
>> 
>> ~~~
>> String code = """
>>               public void print(""" + type + """
>>                o) {
>>                   System.out.println(Objects.toString(o));
>>               }
>>               """;
>> ~~~
>> 
>> should be presented like this:
>> 
>> ~~~
>> String code = """
>>               public void print(""" +
>>               type +
>>               """
>>                o) {
>>                   System.out.println(Objects.toString(o));
>>               }
>>               """;
>> ~~~
>> 
>> It's not great, and replace/format is the "right" solution, but if
>> somebody wants to do concatenation, this style does a better job of
>> indicating where the indent prefix ends and the content begins. The
>> delimiter gives a visual indication of where the "block" is located.
> 
> I appreciate that you want to position an opening delimiter to the left of its content, but can you say why you want `type +` on its own line? What's the big deal with `...""" + type +\n` and then the next text block? (You don't seem to object to the closing delimiter sharing a line with content, since you have ` + ` after the first closing delimiter.)

Just a feeling that it might read better with every piece on a separate line. I don't have a strong preference about that, though.

In retrospect, here's how I'd really write it in a program of mine, assuming I was opposed to the replace/format approach for some reason:

String code = "public void print(" + type + " o) {\n" +
             """
                 System.out.println(Objects.toString(o));
             }
             """;

But that doesn't do such a good job of illustrating how the re-indentation algorithm impacts whitespace before the 'o'. :-)



More information about the amber-spec-observers mailing list