- package FaceToObject;
public class Test3 {
public static void main(String[] args) {
Integer i1 = 123;//Integer i1 = i1.valueOf(123);自动装箱
int i2 = i1;//int i2 = i1.intVlaue();自动拆箱
IntTest it = IntTest.valueOf(123);
IntTest ii = 123;//能否实现自动装箱?
int i = it;//能否自动实现自动拆箱?
System.out.println(it);
}
}
class IntTest {
private final int value;
public IntTest(int value) {
this.value = value;
}
public static IntTest valueOf(int i){
return new IntTest(i);
}
public int intValue() {
return value;
}
@Override
public String toString() {
return String.valueOf(value);
}
}