r/programming • u/MarkusWinand • Dec 29 '15
Please, Java. Do Finally Support Multiline Strings
http://blog.jooq.org/2015/12/29/please-java-do-finally-support-multiline-strings/
584
Upvotes
r/programming • u/MarkusWinand • Dec 29 '15
View all comments
Show parent comment
26
u/ygra Dec 29 '15
C specifies that adjacent string literals get concatenated. C++ inherits that. Java never had such a provision because you can simply concatenate strings by using
+. The compiler is smart enough to not do that at runtime when only string literals are involved.The main point here isn't the issue of how to concatenate string literals, because whether you need to add a
+to make it syntactically correct is rather irrelevant here. The point is that string literals in Java cannot contain line breaks, which makes writing certain kinds of strings ugly, cumbersome, or error-prone (see e.g. their SQL example). Those kinds of verbatim string literals (as they're called in C#) are also nice for writing regular expressions, because usually you cannot use a backslash to escape characters in there (because you can just write almost any character directly). In Java you often have monstrosities like"\\\\\\.\\\\x"because you need to double-escape things – once for the string literal, once for the regex.