String Concatenation and Autoboxing in Java
问题 When you concatenate a String with a primitive such as int, does it autobox the value first. ex. String string = "Four" + 4; How does it convert the value to a string in Java ? 回答1: To see what the Java compiler produces it is always useful to use javap -c to show the actual bytecode produced: For example the following Java code: String s1 = "Four" + 4; int i = 4; String s2 = "Four" + i; would produce the following bytecode: 0: ldc #2; //String Four4 2: astore_1 3: iconst_4 4: istore_2 5: new