关于int和Integer的易错题

111 阅读1分钟

问题

int a = 100;
int b = 100;
​
int c = 200;
int d = 200;
​
Integer m = 100;
Integer n = 100;
​
Integer x = 200;
Integer y = 200;
​
System.out.print(a == b);
System.out.print(c == d);
System.out.print(m == n);
System.out.print(x == y);
System.out.print(a == m);
System.out.print(c == x);

那么6句输出语句输出的结果是什么呢?

答案

true true true false true true

原因

在Integer的源码里,规定了Integer的取值范围是-128~127