ceedee
09/28/2023, 8:50 AMObserver<T>
.
With Kotlin 1.8 one could write such a derived class like this:
class ObservableObserver<T : Any?> : Observer<T> {
override fun onNext(t: T) { ... }
...
}
Kotlin 1.9 requires (probably because of the @NonNull annotation in the interface) a non-nullable type:
class ObservableObserver<T : Any?> : Observer<T> {
override fun onNext(t: T & Any) { ... }
...
}
The RxJava implementation looks crappy, because they declare the data to be passend through Observers as non-nullable but themselves pass on null
in classes like `DeferredScalarDisposable`:
public final void complete(T value) {
int state = get();
if ((state & (FUSED_READY | FUSED_CONSUMED | TERMINATED | DISPOSED)) != 0) {
return;
}
Observer<? super T> a = downstream;
if (state == FUSED_EMPTY) {
this.value = value;
lazySet(FUSED_READY);
a.onNext(null);
} else {
lazySet(TERMINATED);
a.onNext(value);
}
if (get() != DISPOSED) {
a.onComplete();
}
}
Is there a way to still use RxJava in derived Kotlin classes, or is it now required to implement RxJava classes in Java and use the interop features for any communication to Kotlin?