Disposable.dispose() 是幂等的意味着什么?

What it means for Disposable.dispose() to be idempotent?

RxJava documentation for Disposable.dispose

Dispose the resource, the operation should be idempotent.

并且根据维基百科的定义Idempotence

Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application.

是否意味着在同一个 Disposable 上多次调用 dispose() 方法不会有任何附加效果?会不会只处理一次相关资源?

这引发了另一个问题 - 那么 isDisposed() 方法的必要性是什么?不是为了在再次处理一次性物品之前检查是否处理过吗?

您回答了自己的问题。

Does it mean calling dispose() method on same Disposable multiple times will not have any additional effects? Will it dispose related resources only once?

这是正确的。 关于isDisposed()方法,其目的可能是在开始使用之前检查资源是否已被释放。

  1. 是的,就是这样。

  2. isDisposed() 不会阻止任何人调用 dispose() 两次。考虑调用一个无条件调用 dispose()...

    的方法