public class Test {
public static void main(String[] args) throws IOException {
String s1="t";
String s2="m";
}
}
Compiled from "Test.java"
public class typ.Test extends java.lang.Object{
public typ.Test();
Code:
0: aload_0
1: invokespecial #8; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]) throws java.io.IOException;
Code:
0: ldc #19; //String t 进入操作数栈顶
2: astore_1 //String t 出操作数栈,赋值给变量1,即s1
3: ldc #21; //String m 进入操作数栈顶
5: astore_2 //String m 出操作数栈,赋值给变量2,即s2
6: return
}
public class Test {
public static void main(String[] args) throws IOException {
String s1="t";
String s2="t";
}
}
Compiled from "Test.java"
public class typ.Test extends java.lang.Object{
public typ.Test();
Code:
0: aload_0
1: invokespecial #8; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]) throws java.io.IOException;
Code:
0: ldc #19; //String t 进入操作数栈顶
2: astore_1 //String t 出操作数栈,赋值给变量1,即s1
3: ldc #19; //String t 进入操作数栈顶
5: astore_2 //String t 出操作数栈,赋值给变量2,即s2
6: return
}
public class Test {
public static void main(String[] args) throws IOException {
String s1="tm";
String s2="t"+"m";
}
}
Compiled from "Test.java"
public class typ.Test extends java.lang.Object{
public typ.Test();
Code:
0: aload_0
1: invokespecial #8; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]) throws java.io.IOException;
Code:
0: ldc #19; //String tm 进入操作数栈顶
2: astore_1 //String tm 出操作数栈,赋值给变量1,即s1
3: ldc #19; //String tm 进入操作数栈顶
5: astore_2 //String tm 出操作数栈,赋值给变量2,即s2
6: return
}
Compiled from "Test.java"
public class typ.Test extends java.lang.Object{
public typ.Test();
Code:
0: aload_0
1: invokespecial #8; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]) throws java.io.IOException;
Code:
0: ldc #19; //String t 进入操作数栈顶
2: astore_1 //String t 出操作数栈,赋值给变量1,即tmp
3: ldc #21; //String m 进入操作数栈顶
5: astore_2 //String m 出操作数栈,赋值给变量2,即s1
6: new #23; //class java/lang/StringBuilder 创建StringBuilder类型对
象 9: dup
//复制栈顶一个字长的数据,将复制后的数据压栈 10: aload_1 //tmp 进入操作数栈顶
11: invokestatic #25; //Method java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
14: invokespecial #31; //Method java/lang/StringBuilder."<init>":(Ljava/lang/String;)V
17: ldc #21; //String m
19: invokevirtual #34; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
22: invokevirtual #38; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
25: astore_3
26: return
}
用javap命令反编译来分析字符串问题,布布扣,bubuko.com
原文:http://blog.csdn.net/dreamrealised/article/details/26555207