Can you set an object to null in Java?

Setting an object to null, clears the reference . If there is no longer any reference to that object, as in your first example, the memory can be freed, when the JVM runs the GC (Grarbage Collector) the next time.

Sizin İçin Seçtik  Can you call equals on null Java?

Leave a Reply

Your email address will not be published. Required fields are marked *