這段程序大概這樣:java
public static void main(String[] args){ int a = 2; System.out.println(a+++a++); }
編譯後的字節碼爲:code
public static void main(java.lang.String[]); descriptor: ([Ljava/lang/String;)V flags: ACC_PUBLIC, ACC_STATIC Code: stack=3, locals=2, args_size=1 0: iconst_2 /*將int型2推送至棧頂*/ 1: istore_1 /*將棧頂int型數值存入第二個本地變量,這裏就是完成a=2的步驟*/ 2: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream; /*獲取指定類的靜態域,並將其值壓入棧頂*/ 5: iload_1 /*將第二個int型本地變量推送至棧頂,如今棧頂的值爲a的值 2 */ 6: iinc 1, 1 /*將指定int型變量增長指定值,如今a的值爲3 */ 9: iload_1 /*將第二個int型本地變量推送至棧頂,棧頂的值爲 3 */ 10: iinc 1, 1 /*將指定int型變量增長指定值,如今a爲4*/ 13: iadd /*將棧頂兩int型數值相加並將結果壓入棧頂,前面壓入棧頂的值分別爲2和3,因此如今棧頂的值爲 5 */ 14: invokevirtual #3 // Method java/io/PrintStream.println:(I)V 17: return LineNumberTable: line 4: 0 line 5: 2 line 6: 17 } SourceFile: "Test.java"
如今,若是把程序換一下:ip
public static void main(String[] args){ int a = 2; System.out.println(a+++(++a)); }
如今字節碼爲:get
public static void main(java.lang.String[]); descriptor: ([Ljava/lang/String;)V flags: ACC_PUBLIC, ACC_STATIC Code: stack=3, locals=2, args_size=1 0: iconst_2 1: istore_1 /*完成a=2的賦值*/ 2: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream; 5: iload_1 /*a的值壓入棧頂,爲 2 */ 6: iinc 1, 1 /*a自增加 a=3*/ 9: iinc 1, 1 /*a自增加 a=4*/ 12: iload_1 /*a值壓入棧頂,爲 4*/ 13: iadd /*兩值相加,爲 6*/ 14: invokevirtual #3 // Method java/io/PrintStream.println:(I)V 17: return LineNumberTable: line 4: 0 line 5: 2 line 6: 17 } SourceFile: "Test.java"