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

Dan Smith daniel.smith at oracle.com
Wed May 15 17:17:31 UTC 2019


> On May 14, 2019, at 5:25 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
> 
>> Most of the examples in the JEP follow these rules as a convention already. The concatenation examples would benefit from following it.
> 
> Sorry, not seeing it — how would the concatenation examples benefit?  Example?
> 

Sure, let me elaborate.

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.

Further illustrations: Things like this are following the convention I'm proposing we enforce:

~~~
String html = """
              <html>
                  <body>
                      <p>Hello, world</p>
                  </body>
              </html>
              """;
~~~

As is this:

~~~
"""
line 1
line 2
line 3"""
~~~

This one doesn't, but it's a simple matter of putting some spaces before the closing delimiter to fix it:

~~~
String empty = """
""";
~~~

This concatenation example follows the convention (although note that there's no newline between '{' and 'System'):

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



More information about the amber-spec-experts mailing list