From be6e804616439025d65e454a1a2e6a4bff0243c3 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Tue, 19 Nov 2024 19:26:17 -0800 Subject: [PATCH] Add docs for StringConcatToTextBlock PiperOrigin-RevId: 698226007 --- docs/bugpattern/StringConcatToTextBlock.md | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 docs/bugpattern/StringConcatToTextBlock.md diff --git a/docs/bugpattern/StringConcatToTextBlock.md b/docs/bugpattern/StringConcatToTextBlock.md new file mode 100644 index 00000000000..7a4aba0a314 --- /dev/null +++ b/docs/bugpattern/StringConcatToTextBlock.md @@ -0,0 +1,30 @@ +Using [text blocks] for strings that span multiple lines can make code easier to +read. + +For example, prefer this: + +```java +String message = + """ + 'The time has come,' the Walrus said, + 'To talk of many things: + Of shoes -- and ships -- and sealing-wax -- + Of cabbages -- and kings -- + And why the sea is boiling hot -- + And whether pigs have wings.' + """; +``` + +instead of this: + +```java +String message = + "'The time has come,' the Walrus said,\n" + + "'To talk of many things:\n" + + "Of shoes -- and ships -- and sealing-wax --\n" + + "Of cabbages -- and kings --\n" + + "And why the sea is boiling hot --\n" + + "And whether pigs have wings.'\n"; +``` + +[text blocks]: https://docs.oracle.com/en/java/javase/23/text-blocks/index.html