連接:https://www.zhihu.com/question/31203609/answer/51473602
java
Java基本類型共有八種,基本類型能夠分爲三類,字符類型char,布爾類型boolean以及數值類型byte、short、int、long、float、doublegit
在經過valueOf方法建立Integer對象的時候,若是數值在 [-128,127] 之間,便返回指向IntegerCache.cache中已經存在的對象的引用;不然建立一個新的Integer對象。github
Integer、Short、Byte、Character、Long這幾個類相似;app
public class Main { public static void main(String[] args) { Integer i1 = 100; Integer i2 = 100; Integer i3 = 200; Integer i4 = 200; System.out.println(i1==i2); System.out.println(i3==i4); } }
因此上述代碼輸出結果:
true
falsespa
輸出結果代表 i1 和 i2 指向的是同一個對象,而 i3 和 i4 指向的是不一樣的對象。指針
http://alexyyek.github.io/2014/12/29/wrapperClass/對象