Everything that I have read about the java finalize method says NOT to use it. It seems that it is almost never guaranteed to be called and may present problems even when it is.
There are a few other questions that ask when to use it, and it seems the general consensus is NEVER.
I have never used it myself (mainly because of the warnings not to), and I haven't seen it used anywhere.
Are there any cases at all where it would be appropriate? Are there cases where there is no alternative?
If not, why is it there? Are there internal classes that do use it and require the method to be available? Or is it just something that shouldn't be there?
I'm not so much interested in when I should use it (which has been answered with "never"), but clarification on why it is even there given that answer of "never". If it is so useless and dangerous, why hasn't it been depreciated and removed?
Backwards compatibility. Someone first thought it would be a good idea, and then when the world realized it was not such a great idea, it was too late.
These things are barely ever removed. Java is full of concepts that are considered bad idea nowadays but haven't been removed nevertheless - some more examples that come to my mind are clone()
or Thread.stop()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With