0

I've heard (can't find the source) that starting on Java 5 statements such as

String a = "a" + "B" + "c"; were actually optimized by the compiler into String a = "aBc";

But I can't find it online.

Can you help a sister out?

Could you please reconsider marking my question as a duplicate? The question marked as dup actually is the behavior of the compiler, NOT the reference to the docs, which is my question about.

Also, my question asks when this behavior started, which is not addressed by the question marked as dup.

11
  • You want us to find the source of that statement? Commented Jul 9, 2014 at 17:34
  • Just for the record, I am not being lazy. I did spend a considerable amount of time and there are some references on the web, but I can't find a good source, such as a JSR doc, or an Oracle page. Commented Jul 9, 2014 at 17:36
  • 3
    @CindyLangdon: Did you try the language specification, and look for "constant"? Note that this was not new in Java 5. I believe it's been the case forever. Commented Jul 9, 2014 at 17:37
  • 1
    stackoverflow.com/questions/8581824/…, docs.oracle.com/javase/specs/jls/se5.0/html/… Commented Jul 9, 2014 at 17:38
  • 1
    @CindyLangdon Actually, it's a source code transformation. The VM has no clue that a was formed by the concatenation of several strings. It's all taken care of by the compiler. Unless that's what you meant by "optimization for the VM"? Commented Jul 9, 2014 at 17:40

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.