今天发现了一个比较有趣的问题,具体如下:- package bing;
- /**
- * @author bing
- * 关于int、Integer地址比较
- */
- public class IntAndInteger {
-
- static int out = 1000 ;
-
- public static void main(String[] args) {
- int inner1 = 1000 ;
- int inner2 = 1000 ;
-
- Integer inner3 = 1000 ;
- Integer inner4 = 1000 ;
-
- Integer inner5 = 100 ;
- Integer inner6 = 100 ;
-
- System.out.println(out==inner1); //true
-
- System.out.println(inner1==inner2); //true
-
- System.out.println(inner1==inner3); //true
-
- System.out.println(inner3==inner4); //false
-
- System.out.println(inner5==inner6); //true
-
- }
- }
复制代码 |