DevinLei / blog-comments

0 stars 0 forks source link

探究java Integer的实现 - 逻各斯与努斯博客 #34

Open DevinLei opened 5 years ago

DevinLei commented 5 years ago

https://devinlei.github.io/java/2018/12/22/java-integer.html

我们先来看一个例子

public static void main(String[] args) {
    Integer a = 1,b=2;
    System.out.println("交换前a="+a+ ",b="+b);
    // 交换a,b值
    exchange(a,b);
    System.out.println("交换后a="+a+ ",b="+b);
}
public static void exchange(Integer o1,Integer o2){
  Integer temp = o1;
  o1=o2;
  o2=temp;
} 运行结果:

        交换前a=1,b=2
        交换后a=1,b=2