C++ defines elements called destructors, which are automatically executed when an object is destroyed. Is the finalize( ) method similar to a destructor?
Answer:
Java does not have destructors. Although it is true that the finalize( ) method has a similar function to a destructor, it is not the same thing. For example, a C++ destructor is always called immediately before an object goes out of scope, but we have no way of knowing when finalize( ) will be called for any specific object.
To be honest, because of Java's use of the garbage collector, a destructor isn't that necessary.
The above is the detailed content of Ask the Expert - Destroyers. For more information, please follow other related articles on the PHP Chinese website!