/** Finalization is deprecated for removal (JEP 421) but still on by default. */ public class FinalizerProbe { static volatile boolean ran; @SuppressWarnings("removal") @Override protected void finalize() { ran = true; } public static void main(String[] args) throws Exception { new FinalizerProbe(); for (int i = 0; i < 50 && !ran; i++) { System.gc(); Thread.sleep(20); } System.out.println("finalize() ran: " + ran); } }