Skip to content

Instantly share code, notes, and snippets.

@stuart-marks
Created April 28, 2022 02:26
Show Gist options
  • Save stuart-marks/280ab35426caf7c0c362df53ea7d3719 to your computer and use it in GitHub Desktop.
Save stuart-marks/280ab35426caf7c0c362df53ea7d3719 to your computer and use it in GitHub Desktop.
import java.util.*;
public class EmptyFinalizer {
static class A {
protected void finalize() {
System.out.println(this + " was finalized");
}
}
static class B extends A {
}
static class C extends B {
protected void finalize() { }
}
static class D extends C {
}
static class E extends D {
protected void finalize() {
System.out.println(this + " was finalized");
}
}
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
new A();
new B();
new C();
new D();
new E();
}
for (int i = 0; i < 10; i++) {
System.gc();
try {
Thread.sleep(100L);
} catch (InterruptedException ie) { }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment