Created
April 28, 2022 02:26
-
-
Save stuart-marks/280ab35426caf7c0c362df53ea7d3719 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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