-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathK_K.java
More file actions
38 lines (34 loc) · 1.35 KB
/
K_K.java
File metadata and controls
38 lines (34 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.jvm;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//P316
public class K_K {
static Logger logger = LoggerFactory.getLogger(K_K.class);
@Test
public void test01(){
Integer min = new Integer(12);
Integer big = new Integer(52456);
System.out.println(min.equals(12));
System.out.println(big.equals(52456));
}
public static void main(String[] args) {
String a1 = null;
logger.info("{}", a1);
Integer a = 1;
Integer b = 2;
Integer c = 3;
Integer d = 3;
Integer e = 321;
int ei = 321;
Integer f = 321;
Long g = 3L;
System.out.println(c == d); //封装类 == 比较,比较地址。-128<= 封装类 < 127 的时候读取缓存中的封装类,地址相等
System.out.println(e == f); //封装类值大于127,都是重新new对象,地址不相等
System.out.println(ei == f); // + - * / == 都会自动拆箱,比较数值
System.out.println(c == (a + b));
System.out.println(c.equals(a + b)); //equals(Object obj) 形参是对象,a+b自动装箱,封装类比较
System.out.println(g == (a + b)); //类型不一样也是自动拆箱,比较数值
System.out.println(g.equals(a + b)); //封装类.equals()都是封装类比较
}
}