我有以下代码:
public class Tests {
public static void main(String[] args) throws Exception {
int x = 0;
while(x<3) {
x = x++;
System.out.println(x);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我们知道他应该只是写x++
或者x=x+1
,但是x = x++
它首先要归于x
自身,然后再增加它.为什么x
继续0
作为价值?
--update
这是字节码:
public class Tests extends java.lang.Object{
public Tests();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]) throws java.lang.Exception;
Code:
0: iconst_0
1: istore_1
2: iload_1
3: iconst_3
4: if_icmpge 22
7: iload_1 …
Run Code Online (Sandbox Code Playgroud) 示例代码在这里:
static class stack
{
int top=-1;
char items[] = new char[100];
void push(char x)
{
if (top == 99)
System.out.println("Stack full");
else
items[++top] = x;
}
}
Run Code Online (Sandbox Code Playgroud)
当 items[++top] 出现时到底发生了什么?