If you want to mimic in Java the functionality of Cs destruc

If you want to mimic in Java the functionality of C++\'s destructor method (i.e., it gets called as soon as you are finished using an object), why is the finalize method the wrong way to implement this functionality?

Solution

In java there is no equivalent to destructor, because you can\'t predict when (or even if) and object is going to be destroyed and this is because of the reason that java is a garbage collector language.

Finalize method is wrong way to implement because this method is called in the watch of garbage collector for classes that need to explicitly tidy up, the convention is to define a close method and use finalize only for sanity checking, which means if a close is called do it now or log an error.

If you want to mimic in Java the functionality of C++\'s destructor method (i.e., it gets called as soon as you are finished using an object), why is the finali

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site