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