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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章