Here's some simple Java code:
String s = new StringBuilder().append("a").append("b").append("c").toString();
I compile it with JRE 1.6, and I observe the following in the decompiled class file:
String s = "a" + "b" + "c";
I had the following questions:
It's the other way round. +
for String
is implemented using StringBuilder
(or StringBuffer
) behind the scenes (see http://docs.oracle.com/javase/7/docs/api/java/lang/String.html or http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.18.1).
Thus, once they're compiled, your two code snippets are indistinguishable. The decompiler has to make a guess at the original form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With