Skip to content

Latest commit

 

History

History
26 lines (22 loc) · 1.82 KB

File metadata and controls

26 lines (22 loc) · 1.82 KB

Overview

  1. Key points about Java 14+ Text blocks

Idioms

  1. The least indented line controls indentation
  2. Use .indent(n) to manually force indentation
  3. Trailing space on each line is auto-trimmed by the compiler
    1. there are idioms to retain some trailing spaces like character fence and \s chars
  4. -Xlint:text-blocks compiler flag can catch common misuse
  5. Don't align with the opening/starting """
    1. there's no point
    2. opening """ does NOT affect indentation
    3. it makes refactoring unsafe (eg. variable length change affects indentation)
  6. Avoid .stripIndent() since it just does what they compiler already does
    1. rare edge case: reading text block from Standard.in or a file
  7. Put the closing """ in one of two places
    1. After the final character of text
      1. Text block will end with the final character of the text
    2. On the line after the final char of the text, aligned with the last line
      1. Text block will end with a \n

Other Resources

  1. https://openjdk.org/jeps/378
  2. https://docs.oracle.com/en/java/javase/15/text-blocks/index.html