Is it possible to set an Object to be null from within itself?

后端 未结 7 2027
情书的邮戳
情书的邮戳 2021-02-07 07:06

I know that this = null is illegal.

I\'m wondering if there\'s some other way to have an object clean itself up.

my desire is to be able to do some

7条回答
  •  深忆病人
    2021-02-07 08:09

    This neat question is technically interesting. However, considering your intent: You are attempting to force the condition of all references being null so that you can guard against the invalid use of an otherwise expired instance.

    It is bad practice to assign any meaning to null.

    Instead, modify (or facade if you can't modify) your A object so that some other flag is available. For example public boolean isClosed() ...

提交回复
热议问题