finalize()

I read a comment from Java 2 Exam Prep by Bill Brogden. he said "when extending a class that has a finalize method you MUST write a finalize that executes super.finalize()".

is it true? my compiler or VM did not compain about it.

Thanks,
embertAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AMD_MANCommented:

Check out:

http://java.sun.com/docs/books/tutorial/java/javaOO/garbagecollection.html

It states:
"The finalize method is a member of the Object class, which is the top of Java's class hierarchy and the parent of everything. A class can override the finalize method to perform any finalization necessary for objects of that type. If you override finalize, then your implementation of the method should call super.finalize as the last thing it does"

This only makes sense. If you are using finalize, possibly classes you inherit from may also use it.  This seems similar to the way destructors are called in C++.

The VM or compiler may not complain in your specific case.  But there may be situations out there where finalizing the super class is needed (the class closes a file/socket/whatever).

Good luck!
AMD_MAN
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.