java中j=j++的问题

public class Abnormal {
   
    public static void main(String[] args) {

        int count = 0;

        for (int i = 0; i < 100; i++) {

            count = count++;

        }

        System.out.println(count);
	}
}

public static void main(java.lang.String[]);
descriptor: ([Ljava/lang/String;)V
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=3, args_size=1
0: iconst_0
1: istore_1
2: iconst_0
3: istore_2
4: iload_2
5: bipush 100
7: if_icmpge 21
10: iload_1
11: iinc 1, 1
14: istore_1
15: iinc 2, 1
18: goto 4
21: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
24: iload_1
25: invokevirtual #3 // Method java/io/PrintStream.println:(I)V
28: return
LineNumberTable:
line 7: 0
line 9: 2
line 11: 10
line 9: 15
line 15: 21
line 16: 28
StackMapTable: number_of_entries = 2
frame_type = 253 /* append */
offset_delta = 4
locals = [ int, int ]
frame_type = 250 /* chop */
offset_delta = 16
}

  从字节码中,iload2 变量即为count,2表示局部变量的索引,iinc 2, 1表示将栈顶变量2自增1(栈顶变量只是副本),但是并没有istore2存回本地变量。

原文地址:https://www.cnblogs.com/wqkant/p/13985930.html