我发现Java支持原始类型的常量折叠,但是String
s呢?
例子
如果我创建以下源代码
out.write(""
+ "<markup>"
+ "<nested>"
+ "Easier to read if it is split into multiple lines"
+ "</nested>"
+ "</markup>"
+ "");
编译后的代码中有什么?
合体版?out.write("<markup><nested>Easier to read if it is split into multiple lines</nested></markup>");
还是效率较低的运行时串联版本?out.write(new StringBuilder("").append("<markup>").append("<nested>").append("Easier to read if it is split into multiple lines").append("</nested>").append("</markup>").append(""));