我有以下测试代码:
public class StringLiteralTest {
static void testPrefix() {
int i = 0;
String prefixConcat = "a" + "b" + i;
}
static void testSuffix() {
int i = 0;
String suffixConcat = i + "c" + "d";
}
}
Run Code Online (Sandbox Code Playgroud)
生成的字节码是:
Compiled from "StringLiteralTest.java"
public class StringLiteralTest {
public StringLiteralTest();
Code:
0: aload_0
1: invokespecial #8 // Method java/lang/Object."<init>":()V
4: return
static void testPrefix();
Code:
0: iconst_0
1: istore_0
2: new #15 // class java/lang/StringBuilder
5: dup
6: ldc #17 …Run Code Online (Sandbox Code Playgroud) java ×1