+ 연산자를 사용하면 버전에 따라서 최적화가 진행된다
String 연산은 1.4 버전까지 매우 비용이 많이 드는 연산이었다.
이후 J2SE 5.0 버전 부터 Compile 할 때 String 연산 작업을 StringBuilder 를 이용해 바이트 코드를 변경하여 최적화 해준다.
Java SE 9 버전 부터는 컴파일 시점에 바이트 코드를 변경하지 않고 런타임 시점에 String을 연산하는 전략을 바꿀 수 있도록 invokedynamic, StringConcatFactory을 사용하도록 변경했다.
https://p829911.tistory.com/18

String 연산 작업을 StringBuilder 를 이용해 바이트 코드를 변경하여 최적화 해준다


From Java 9 (Java Enhancement Proposal 280 or JEP 280) , the entire StringBuilder append sequence has been replaced with a simple invokedynamic (More on this in next section below) call to java.lang.invoke.StringConcatFactory, that will accept the values in the need of concatenation.
6가지의 전략이 있는데 default는 MH_INLINE_SIZE_EXACT이다.
-Djava.lang.invoke.stringConcat=<strategyName> 을 시스템 속성으로 지정하여 실행하면 이 전략을 변경할 수 있다.
https://medium.com/javarevisited/java-compiler-optimization-for-string-concatenation-7f5237e5e6ed