A
A
artem2020-09-28 13:44:36
Java
artem, 2020-09-28 13:44:36

Why does the finalize() method throw an error?

class gomel {
  int x;

  gomel (int i) {
    x = i;
  }

  protected void finalize() {
    System.out.println("Финализация " + x);
  }

  void generator(int i) {
    gomel o = new gomel(i);
  }
}

public class giblar {
  public static void main(String[] args) {
    int count;

    gomel ob = new gomel(0);

    for(count = 1; count < 100000; count ++) {
      ob.generator(count);
    }
  }
}


In the console when compiling, it gives:
Note: giblar.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
How to solve it? JDK Version 11.0.8

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-09-28
@arteqrt

Because finalize has been deprecated for a very long time, deprecated and will someday be completely removed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question