java中[i=i++]问题

1
2
3
4
5
6
7
8
9
package tech.mapan;

public class add {
public static void main(String[] args) {
int i = 10;
i = i++;
System.out.println(i);
}
}

输出结果为10,反编译结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Compiled from "add.java"
public class tech.mapan.add {
public tech.mapan.add();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return

public static void main(java.lang.String[]);
Code:
0: bipush 10
2: istore_1
3: iload_1
4: iinc 1, 1
7: istore_1
8: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
11: iload_1
12: invokevirtual #3 // Method java/io/PrintStream.println:(I)V
15: return
}
1
2
3
4
5
6
7
8
9
package tech.mapan;

public class add {
public static void main(String[] args) {
int i = 10;
i = ++i;
System.out.println(i);
}
}

输出结果为11,反编译结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Compiled from "add.java"
public class tech.mapan.add {
public tech.mapan.add();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return

public static void main(java.lang.String[]);
Code:
0: bipush 10
2: istore_1
3: iinc 1, 1
6: iload_1
7: istore_1
8: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
11: iload_1
12: invokevirtual #3 // Method java/io/PrintStream.println:(I)V
15: return
}