包装类型来自于八个基本类型一一对应。
基本类型 包装类型
byte Byte
int Integer
short Short
float Float
boolean Boolan
char Character
long Long
double Double
package Singleton_mode;
public class pagake {
public static void main(String[] args) {
int a = 123;
Integer i = new Integer(123); //自动封装,拆箱
System.out.println(a==i);
}
}
package Enumone;
public class IntegertTest {
public static void main(String[] args) {
int i = 1;
Integer o = 1;
System.out.println(i==o);
int y = 123;
Integer h = new Integer("123");
System.out.println(h==y);
int p = 456;
int l = Integer.parseInt("456");
System.out.println(l==p);
Integer l2 = new Integer("456");
Integer l1 = Integer.parseInt("456");
System.out.println(l1==l2);
System.out.println(l1.equals(l2));
}
}
true
true
true
false
true