0

package com.java.gc;

public class FinalizeDemo { static FinalizeDemo s;

public static void main(String[] args) throws InterruptedException
{
    FinalizeDemo f = new FinalizeDemo();
    System.out.println("f hashcode:" +f.hashCode());
    f=null;
    System.gc();
    Thread.sleep(5000);

    System.out.println("s hashcode:"+s.hashCode());
    s=null;
    Thread.sleep(10000);
    System.out.println("ENd of main");

}
public void finlaize()
{
    System.out.println("Finlaize method called");
    s=this;
}

}

Getting NPE while runnig this code , can anyone please help me?

Prags
  • 2,457
  • 2
  • 21
  • 38
Ankit
  • 1
  • 3
  • What do you intend to achieve with this code? It looks kind of unstructured. –  Jun 17 '18 at 05:48
  • Even if this wouldn't be another duplicate of that question... Please read [mcve] and enhance your question accordingly. Don't just throw some code at us and "not working". It is absolutely unclear what this code is supposed to do or result in. – GhostCat Jun 17 '18 at 05:51
  • You have a typo in `finlaize` should be `finalize`. Be aware though that `finalize` is deprecated starting with java 9. – vstm Jun 17 '18 at 06:08

0 Answers0