This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

finalize()??  RSS feed

 
Wentao Liang
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howby!
Just now I create a new class which is inside a finalize() method,when compiling,there is a error. Why I should use the "protected" before the method??
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
show your code,
show the error,
 
Shivit Agarwal
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Wentao Liang:
Howby!
Just now I create a new class which is inside a finalize() method,when compiling,there is a error. Why I should use the "protected" before the method??


Because finalize() has this general form :

protected void finalize()
{
// your finalization code
}
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't given any details of what you're doing, but note that the Java custom finalisation mechanism (the overridable finalize() method) is generally not very useful. It comes from the earliest days of Java and it isn't very fit for purpose.

There are a few times when custom finalisation can be useful. But these are generally not the types of things that beginners should think about at all.

If you are indeed a beginner, the chances are that you are wrong in thinking you need to use finalize(). So please tell us more about what you are trying to achieve.
 
Wentao Liang
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!I have got the reason why I was wrong!
Thanks again for your replies!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!