1. Summarize the problem
I've heard String + operation will be changed when compiling after JDK 1.5.
But sadly I couldn't find the optimization case.
What did I miss? What did I do wrong?
2. Describe what you’ve tried
I used IntelliJ IDEA 2021.2 (Ultimate Edition), Java 8.
and Decompile by Intellij 52.0 version (Java 8).
The results have not changed at all.
and was no different on the online web decompiler site.
This is what I tried.
public static void main(String[] args) {
String str0 = "It's a string....";
String str1 = "It's" + " a string" + "....";
String str2 = "It's a string...." + str0 + "000";
str2 = str0 + str1 + "1111";
str2 = str2 + "1111";
str2 += "1111";
for (int i = 0; i < 10; i++) {
str2 = str2 + "1111";
str2 += "1111";
}
}
3. When appropriate, show some code
I would like to confirm that not all String classes are changed, but at least one case will be converted.
This is what I want.
public static void main(String args[]) {
String str0 = "It's a string....";
String str1 = "It's a string....";
String str2 = (new StringBuilder("It's a string....")).append(str0).append("000").toString();
str2 = (new StringBuilder(String.valueOf(str0))).append(str1).append("1111").toString();
str2 = (new StringBuilder(String.valueOf(str2))).append("1111").toString();
str2 = (new StringBuilder(String.valueOf(str2))).append("1111").toString();
for(int i = 0; i < 10; i++) {
str2 = (new StringBuilder(String.valueOf(str2))).append("1111").toString();
str2 = (new StringBuilder(String.valueOf(str2))).append("1111").toString();
}
}
Thanks for reading, and thanks for the help.