mirror of
https://github.com/corda/corda.git
synced 2025-01-04 04:04:27 +00:00
35 lines
545 B
Java
35 lines
545 B
Java
|
public class Finalizers {
|
||
|
private static boolean finalized = false;
|
||
|
|
||
|
private static void expect(boolean v) {
|
||
|
if (! v) throw new RuntimeException();
|
||
|
}
|
||
|
|
||
|
protected void finalize() {
|
||
|
finalized = true;
|
||
|
}
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
new Finalizers();
|
||
|
|
||
|
expect(! finalized);
|
||
|
|
||
|
System.gc();
|
||
|
|
||
|
expect(finalized);
|
||
|
|
||
|
new Finalizers2();
|
||
|
|
||
|
finalized = false;
|
||
|
|
||
|
expect(! finalized);
|
||
|
|
||
|
System.gc();
|
||
|
|
||
|
expect(finalized);
|
||
|
}
|
||
|
|
||
|
private static class Finalizers2 extends Finalizers { }
|
||
|
|
||
|
}
|