Inheriting finialize()
hi,
i came across an article by a dev team member of Java Hotspot VM, Tony Printezis regarding behaviour finalize() and how to avoid it. The article is present at: http://www.devx.com/Java/Article/30192
the author states something like this:
class A
{
finalize()
{
// do something here
}
}
class Bextends A
{
// does not have an explicit finalize() of its own
}
In this scenario, B will inherit finalize()
from A and will be added to the finalization queue.
My question is, what about the following case:
class C
{
// does not have its own finalize()
}
Now class C automatically extends from class Object, which in turn has an empty, but concrete finalize()
method.
Why does C (or for that matter any class) not get added to the finalization queue?
Does the JVM behave differently for classes extending Object from those extend other classes?
regards,
-Piyush
[1463 byte] By [
p77gina] at [2007-11-27 5:47:19]

# 2
> Efficiency. The finalize method of the Object class
> doesn't do anything.
True. And that is understood. Though, to be still able to determine that, the JVM wud have to go through the code of the parent class?
So what I was trying to figure out is, does the JVM actually differentiate between a class inheriting from Object in comparison to one inheriting from some other class.
# 3
> True. And that is understood. Though, to be still
> able to determine that, the JVM wud have to go
> through the code of the parent class?
>
> So what I was trying to figure out is, does the JVM
> actually differentiate between a class inheriting
> from Object in comparison to one inheriting from some
> other class.
The VM will differentiate between classes that do not override the finalize method of class Object (or override it in a trivial way) and classes with non-trivial finalize methods.
YoGeea at 2007-7-12 15:31:37 >
