Class TextBlockExamples

java.lang.Object
net.jrodolfo.java_evolution.java15.TextBlockExamples

public class TextBlockExamples extends Object
Demonstrates text blocks, finalized in Java 15.

Before text blocks, multi-line strings required newline escapes, concatenation, and careful indentation. That made embedded JSON, SQL, HTML, and other structured text hard to read in Java source code.

Text blocks solve this by making multi-line string literals readable and maintainable. Java 15 finalized the feature after previews in Java 13 and Java 14.

  • Constructor Details

    • TextBlockExamples

      public TextBlockExamples()
  • Method Details

    • json

      public String json()
      Creates JSON using a text block.
      Returns:
      multi-line JSON text
    • formattedSummary

      public String formattedSummary(int version, String feature)
      Uses String.formatted(Object...) with a text block template.
      Parameters:
      version - the Java version
      feature - the feature name
      Returns:
      formatted multi-line text