值类型和引用类型

    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;
    }

 

相关文章:

  • 2021-07-25
  • 2021-11-27
  • 2021-11-22
  • 2022-01-25
  • 2021-12-13
  • 2022-02-03
  • 2022-02-22
猜你喜欢
  • 2021-07-02
  • 2022-02-02
  • 2021-06-11
  • 2021-08-23
  • 2022-12-23
相关资源
相似解决方案