解釋:
jvm在計算i++時會產生臨時變量來接收i++的結果,此時相當於將i++的結果賦值到i,i的值被重新賦值了。
測試代碼:
/**
* @author: jorian
* @date: 2020/1/13 22:32
* @description: this is description for the class
*/
public class TestPrintf {
public static void main(String []args){
int i = 0;
int temp = i++;
System.out.println("temp:"+temp);
System.out.println("i:"+i);
}
}
結果:
temp:0
i:1
Process finished with exit code 0