Text blocks for multiline strings
Write multiline strings naturally with triple-quote text blocks.
Porównanie kodu
✕ Java 8
String json = "{\n" +
" \"name\": \"Duke\",\n" +
" \"age\": 30\n" +
"}";
✓ Java 15+
String json = """
{
"name": "Duke",
"age": 30
}""";
Widzisz problem z tym kodem? Daj nam znać.
Dlaczego nowoczesne podejście wygrywa
Readable as-is
JSON, SQL, and HTML look like real JSON, SQL, and HTML in your source.
No escape hell
Embedded quotes don't need backslash escaping.
Smart indentation
Leading whitespace is trimmed automatically based on the closing delimiter position.
Stare podejście
String Concatenation
Nowoczesne podejście
Text Blocks
Od JDK
15
Poziom trudności
Początkujący
Wsparcie JDK
Text blocks for multiline strings
Dostępne
Widely available since JDK 15 (Sept 2020)
Jak to działa
Text blocks let you write multiline strings exactly as they appear. No more escaping quotes or adding \n. The compiler strips incidental indentation automatically.
Powiązana dokumentacja