something pretty silly, like this:
String str = "hello" + " world," + " how " + "are" + "you?"
Of course, sometimes you want to do this, like when you have to split
your string literal across multiple lines. You might do this when
your down the unfortunate path of hard coding SQL statements -- bleh
-- or maintaining old code that does the same.
That made me wish Java had C++ string literal handling. In C++, you can write
string str = "select * "
"from nowhere"
"where "
"something = nothing"
and the compiler will concatenate all those literals for you into a
single string. Much nicer than having all those concatenation
operators floating around.
Even better, though, would be support for other languages' multi-line
string literals -- like Groovy, Scala, Python (I think) etc. So even
better is:
def str = """ select *
from nowhere
where
something = nothing """
Yep, I've wanted this many times too. I figured this would have been one of the small enhancements in Project Coin for Java 7, but alas, it would appear not.
ReplyDelete