我创建的类是否可以自动装箱?
2022-09-01 19:05:32
有没有办法对我创建的类使用自动装箱?例如,我有这个子类。Number
public class UnsignedInteger extends Number {
int n;
public UnsignedInteger(int n) {
if(n >= 0)
this.n = n;
else
throw new IllegalArgumentException("Only positive integers are supported");
}
}
现在,工作得很好,但是有没有办法进行编译:?这对我来说不会。提前致谢!UnsignedInteger i = new UnsignedInteger(88);
UnsignedInteger i = 88;