Java 13 Feature | Text blocks using three double quotes “”” | Examples with multiline HTML, SQL, Paragraph with indentation

In Java 13, new way of defining multiline, large, pre-formatted texts is introduced which is called ‘Text Blocks’. This has been introduced as part of JEP 355. Lets look at examples of this text blocks.

Setup for preview feature

Text blocks in JDK 13 are preview only features i.e. this feature is not enabled by default. If you directly write code to use this, it will give compiler error Text Blocks is a preview feature and disabled by default. Use --enable-preview to enable

If you are using eclipse IDE, then right click on project > Properties > Java Compiler > Uncheck “Use default compliance settings” > Check “Enable preview feature for Java 13”

After enabling preview feature, compiler will continue to give warning You are using a preview language feature that may or may not be supported in a future release  wherever preview features are used.

Multiline HTML with indentation Example

Multiline indented SQL Query Example

Paragraphs with + for longer text lines.

Mix classic string way & Java 13 feature

Leave a Reply

Your email address will not be published. Required fields are marked *