Multi-line string literals delimited by triple quotes, with incidental indentation stripped based on the closing delimiter's position.
The problem it solved
Embedded SQL, JSON and HTML required concatenation with \n and escaped quotes, making the literal unreadable and diffs noisy.
How you did it before
String concatenation across lines with explicit \n and backslash-escaped quotes, or loading the text from a resource file to avoid the mess.
Journey: Preview in 13 (JEP 355) and 14, final in 15.
Asked as
- What problem do text blocks solve, and what are the traps?
- How is incidental indentation determined?
- Do text blocks interpret escape sequences?
Scenario question
A test class holds twelve JSON fixtures as concatenated strings with escaped quotes, and a reviewer asks for text blocks.
What do you watch for in the conversion?
What a good answer weighs
Indentation is computed from the least-indented line including the closing delimiter, so moving that delimiter silently changes the content — and a JSON fixture compared with an exact string will then fail. Trailing spaces are stripped unless escaped. The mature answer also asks whether fixtures that large belong in resource files instead.