26

Why doesn't Java support multi-line strings? I know they dont, but I dont know why. Is there a good reason? Several other languages have this capability, even older ones, so why doesnt Java? As far as I know (not very far) it shouldnt be too had to add this functionality to your lexers/compilers.

Edit: For clarification, I dont mean a string with a newline character in it. I mean something like this:

String s = "Hello
            World";

Edit2: I dont know why people thought I was asking for opinions, I most certainly am not. I specifically asked for good reasons. I suppose I need to explicitly say based on facts as well?

11
  • 4
    Barring a Sun/Oracle employee coming here to answer the question, answers will be entirely opinion-based and conjecture. Commented Mar 28, 2014 at 20:10
  • 4
    @JeffGohlke Sometimes (often) they have good reasons for doing/not doing something. Perhaps someone actually knows, understands, and can explain it. This is why Im asking if there is a good reason, not just an arbitrary reason Commented Mar 28, 2014 at 20:12
  • 1
    By the way, see also the accepted answer at: stackoverflow.com/questions/878573/java-multiline-string?rq=1 Commented Mar 28, 2014 at 20:16
  • 1
    @Dgrin91 Then it seems you did not read the blog post linked to in the answer, which not only discusses that, but would have taken you more than 45 seconds to read. If you are not willing to make the effort to perform that one extra mouse click, then we cannot be expected to make the effort to essentially retype that and similar other articles for you here. Commented Mar 28, 2014 at 20:18
  • 4
    The String you posted. Is that Hello\nWorld or Hello\n World. This is the problem. If it's one or the other, how would you represent the other one? Java wanted to be more well defined than some of these hipster languages doing this. It works a little bit better in python because indentation is part of syntax, so it's less ambiguous when you don't have an arbitrary amount of whitespace that could be syntax. Commented Mar 28, 2014 at 20:27

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.