JEP 378 – Text blocks leave preview in JDK 15

Share

It’s been a year since text blocks made their first foray into the JDK. Now, with JDK 15, JEP 378 will remove the preview status of text blocks and make them a full-fledged feature of Java 15.

Text blocks in Java

JEP 378 is the third JEP to deal with text blocks in the JDK. Let’s take a little look at the history of text blocks over the last year or so.

JEP 355 introduces text blocks as preview feature

The first time text blocks came to the JDK was in Java 13 thanks to JEP 355. A text block is “a multi-line string literal that avoids the need for most escape sequences, automatically formats the string in a predictable way, and gives the developer control over the format when desired.” And when this original JEP landed, it caused some excitement among the community. Indeed, we featured an article by Tim Zöller called Java 13 – why text blocks are worth the wait.

Thanks to JEP 355, text blocks made their way into JDK 13 as a preview feature for the community to try out and provide feedback about. It became clear during this first preview that some use cases needed text blocks to undergo a few changes.

JEP 368 and some important changes

Newline characters and white space were the reasons for the changes made to text blocks in JDK 14. Users discovered that a string spanning multiple lines can prove problematic if newline characters appear in the string. Jim Laskey writes in JEP 368, “One part of a program may be more readable when strings are laid out over multiple lines, but the embedded newline characters may change the behavior of another part of the program. Accordingly, it would be helpful if the developer had precise control over where newlines appear, and, as a related matter, how much white space appears to the left and right of the “block” of text.”

SEE ALSO: Java 15’s latest news

This is why the second preview of text blocks introduced two new escape sequences: <line-terminator> and s. The former escape sequence explicitly suppresses the insertion of a newline character, and the latter translates to a single white space (u0020), allowing it to be used as a buffer to prevent intentionally included white space from being removed.

You can read a more detailed look at JEP 368 here.

JEP 378 – text blocks are ready for launch

SEE ALSO: Project Leyden to bring static images to the Java platform and JDK

The upcoming release of Java 15 means it’s time to take a look at the feedback for preview features such as text blocks. This time around there were no red flags or use cases that resulted in changes to this feature, so Jim Laskey wrote JEP 378 proposing that text blocks leave preview. The JEP was confirmed to target JDK 15 and so text blocks will be a full-fledged feature in Java 15 when it arrives in September.

The post JEP 378 – Text blocks leave preview in JDK 15 appeared first on JAXenter.

Source : JAXenter