简体   繁体   中英

Any Future Plans for Multiline Java String

In the spirit of this question: https://stackoverflow.com/questions/1886966/java-string-declaration-occupying-multiple-lines

will there be any plans in any future version of Java to allow string continuation in the java scource?

String haveUeverSeenLorem =
  "Lorem ipsum dolor sit amet, \
  consectetur adipisicing elit, \
  sed do eiusmod tempor incididunt \
  ut labore et dolore magna aliqua.";

Either one way or another, eg like the above example.

It was proposed for inclusion in Java 7 but was rejected.

It was proposed again for Java 8 but did not make it to the final version.

Java 9's JEP 213: Milling Project Coin does not include anything regarding multine strings either.

It seems very unlikely. They didn't make the cut for Java 7, as noted in the answer to Java 7 - Multiline strings

Update January 2018:

Have a look at JEP 326: Raw String Literals .

The planned syntax will be:

String haveUeverSeenLorem = `Lorem ipsum dolor sit amet, 
consectetur adipisicing elit, 
sed do eiusmod tempor incididunt 
ut labore et dolore magna aliqua.`;

Maybe it will be integrated in the next version of Java (Java 11 in September 2018 would be great).

Update April 2020

The JEP 326: Raw String Literals was withdrawn and is replaced by

JEP 368: Text Blocks (Second Preview) .

This feature is released as a preview language feature in Java 14 .

The supported syntax is:

String json = """
              {
                 "id": 10,
                 "name": "Joe",
                 "birthday": "1970-01-01"
              }
              """;

""" (fat delimiters) are used as delimiters for multiline strings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM