Destroying objects in Java

后端 未结 8 856
走了就别回头了
走了就别回头了 2021-01-22 00:07

I have a general idea of how the Garbage Collector works in Java, but my reasoning for destroying an object is not because I care about freeing up memory, but because of functio

8条回答
  •  感动是毒
    2021-01-22 00:29

    If you are really trying to model the real world as closely as possible, you could add a owner attribute to the dollar, so that when you call dollar.addTo(), you will have to change the owner, the dollar only belongs to one person at any given time.

提交回复
热议问题