javap查看字节码
所属分类 java
浏览量 1345
JavapTest.java
public class JavapTest {
public static void main(String[] args) throws Exception {
int i = 0;
System.out.println(i++);
System.out.println(++i);
String str = "a"+"b";
System.out.println(str);
str = "a"+i+"b";
System.out.println(str);
StringBuilder sb = new StringBuilder();
sb.append("a").append(i).append("b");
System.out.println(sb);
}
}
编译
javac JavapTest.java
运行
java JavapTest
查看字节码
javap -c JavapTest
String str = "a"+"b";
转换成字符串常量 ab
str = "a"+i+"b";
字符串拼接转换成 StringBuilder
Compiled from "JavapTest.java"
public class JavapTest {
public JavapTest();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."":()V
4: return
public static void main(java.lang.String[]) throws java.lang.Exception;
Code:
0: iconst_0
1: istore_1
2: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
5: iload_1
6: iinc 1, 1
9: invokevirtual #3 // Method java/io/PrintStream.println:(I)V
12: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
15: iinc 1, 1
18: iload_1
19: invokevirtual #3 // Method java/io/PrintStream.println:(I)V
22: ldc #4 // String ab
24: astore_2
25: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
28: aload_2
29: invokevirtual #5 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
32: new #6 // class java/lang/StringBuilder
35: dup
36: invokespecial #7 // Method java/lang/StringBuilder."":()V
39: ldc #8 // String a
41: invokevirtual #9 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
44: iload_1
45: invokevirtual #10 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
48: ldc #11 // String b
50: invokevirtual #9 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
53: invokevirtual #12 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
56: astore_2
57: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
60: aload_2
61: invokevirtual #5 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
64: new #6 // class java/lang/StringBuilder
67: dup
68: invokespecial #7 // Method java/lang/StringBuilder."":()V
71: astore_3
72: aload_3
73: ldc #8 // String a
75: invokevirtual #9 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
78: iload_1
79: invokevirtual #10 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
82: ldc #11 // String b
84: invokevirtual #9 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
87: pop
88: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
91: aload_3
92: invokevirtual #13 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
95: return
}
上一篇
下一篇
Java中的整数缓存IntegerCache
JMX之ObjectName
tomcat之JMXProxyServlet
leveldb简介
leveldb要点
一致性算法raft简介