值类型和引用类型

    public static void main(String[] args) {
        setValue();// 1
        setValue2();// 100
    }

    static void setValue() {
        int[] i = new int[1];
        i[0] = 100;
        setA(i);
        System.out.println(i[0]);
    }

    static void setValue2() {
        int i = 100;
        setA(i);
        System.out.println(i);
    }

    ////
    static void setA(int[] x) {
        x[0] = 1;
    }

    static void setA(int x) {
        x = 1;
    }

 

posted on 2016-09-18 16:50  张释文  阅读(154)  评论(0编辑  收藏  举报