我们可以在原始数据类型包装类的实例上调用finalize()吗,例如整数?如果不是,为什么?
Integer i = new Integer(5);
i.finalize(); // compilation error why?
// implicitly all classes are subclassed from Object so why this error?
您为什么/需要呼叫finalize
?您不能,因为方法是protected并且Integer扩展Number而不是直接扩展Object
protected void finalize() throws Throwable { }