Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

finalize()

 
michelle
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
finalize() only call one time
so, finalize() can overload?
 
kaushik banerjee
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
u're bang on target . finalize() can be overlaoded but the one with the original signature will be called.
protected void finalize() throes Throwable
Regards,
Kaushik
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A finalizer is a method from class Object that any class may OVERRIDE. To OVERLOAD method "finalize()" would be futile since when it is used it MUST have the following signature:
protected void finalize() throws Throwable {
//do finalization stuff
}
Remember that although the "finalize()" override MAY be called on dead instances of the associated class before the memory occupied by that object is reused, to guarantee that it will be called is to use the method "System.runFinalizersOnExit(}" in the class as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic