在我看来,编译器将采取这样的做法似乎是合理的:
log.info("A really long logger message that is kind of a pain in the tucous " +
"and violates formatting standards by making the line to long");
并将两个字符串编译成一个。我很确定这是真的,但我想 如果有人提出来,让我的鸭子排成一排。
最佳答案
是的,这将由 constant expression 处理Java 语言规范的一部分。特别参见部分 15.18.1. String Concatenation Operator +
关于Java编译器字符串优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13865030/