java中,i = i++; 打印出i=0

解釋:

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

 

發佈了67 篇原創文章 · 獲贊 11 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章