Do I need to check isDisposed() before calling dispose()?
I don´t think so, if you check i.e. implementation of CompositeDisposable
(of course if you using that class, not another implementation of disposable interface)
there is :
@Override
public void dispose() {
if (disposed) {
return;
}
...rest of method body
@Override
public boolean isDisposed() {
return disposed;
}
So the answer is it depends in what way Disposable interface is implemented, You can check it in JetBrains IDE by right click and go to> implementation
It makes little sense to call isDisposed
. dispose
implementations already do that for you and make sure repeated calls are no-ops or have no detectable effect.
Unfortunately, somebody in the early days of RxJava started writing examples with it and now everybody keeps copying that pattern.
It makes a little more sense to check isDisposed
before calling onNext
for example but you don't get to do that very often outside Observable.create()
.