範例

protected void finalize() throws Throwable {
System.out.println("Not calling super.finalize()"); //$NON-NLS-1$
}

public static void main(String[] args) {
SuperFinalize_Example sf = new SuperFinalize_Example();
sf = null;
Runtime.getRuntime().gc();
}

解決方案
插入 super.finalize() 的呼叫做為 finalize() 方法的最後一個陳述式。

protected void finalize() throws Throwable {
try {
System.out.println("Calling super.finalize()"); //$NON-NLS-1$
} finally {
super .finalize();
}
}

public static void main(String[] args) {
SuperFinalize_Example sf = new SuperFinalize_Example();
sf = null;
Runtime.getRuntime().gc();
}