1

RxJava documentation for Disposable.dispose states

Dispose the resource, the operation should be idempotent.

And according to the Wikipedia definition of 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.

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

That raises another question - what is the need for isDisposed() method then? Isn't it for checking if a disposable is disposed before disposing it again?

army007
  • 551
  • 4
  • 20
  • 2
    "Isn't it for checking if a disposable is disposed before disposing it again?" It's not just for that. Whether something is disposed could be useful for other things too, such as when you want to use it for something, but don't want to use an already-disposed object. – Sweeper Dec 14 '20 at 08:59
  • @Sweeper, got it, thanks. – army007 Dec 14 '20 at 09:08

2 Answers2

3

You answered your own question.

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

This is correct. Regarding the isDisposed() method, its purpose is probably checking whether a resource has been disposed before you begin using it.

Tobias
  • 2,811
  • 2
  • 20
  • 31
1
  1. Yes, that's it.

  2. isDisposed() will not prevent anyone to call dispose() twice. Think about calling a method that inconditionnaly calls dispose()...

Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69