File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes finalize()?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "finalize()??" Watch "finalize()??" New topic
Author

finalize()??

Wentao Liang
Greenhorn

Joined: Oct 05, 2007
Posts: 13
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

Joined: Nov 08, 2007
Posts: 457
show your code,
show the error,


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Shivit Agarwal
Ranch Hand

Joined: Feb 28, 2008
Posts: 82
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
}


Have the determination of mirror which never fails to reflect in spite of being broken into pieces.<br /> <br />Kiss the hands you cannot bite.<br /> <br />An Optimist is one who starts taking a bath when he accidentally falls into the water.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Wentao Liang
Greenhorn

Joined: Oct 05, 2007
Posts: 13
Thanks!I have got the reason why I was wrong!
Thanks again for your replies!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: finalize()??
 
Similar Threads
why finalize() can't be defined as private?
JSP FAQ
Finalize():will garbage collector call finalize() after my code has already called it?
Gc question
Finalization Method