Hello,
When using RxJava in Kotlin.When subscribing to a Single I use the following subscribe() overload
public final fun subscribe( onCallback: ((t1: User!, t2: Throwable!) → Unit)!)
In the implementation I have a following check:
if (t1 == null) return@subscribe
This check generates a compile time warning that (t1==null) is always false
I wonder how does compiler know that at compile time if User! means that t1 can be of type User or User?
Thanks.
Leszek
It looks like you’re trying to specify platform types for User!
and Throwable!
, which is not possible. Is that the actual signature? Here’s the docs on platform types and null safety
Thanks.
Actual signature is:
public final Disposable subscribe(final BiConsumer<? super T, ? super Throwable> onCallback)
which in Kotlin is:
public final fun subscribe( onCallback: ((t1: User!, t2: Throwable!) → Unit)!)
Can you post the code around your if (t1 == null) return@subscribe
line? When a platform type is returned, how you declare it tells the compiler if it should be considered nullable or not.
Sure, this is what I have:
.subscribe { source, _ →
if (source == null) return@subscribe
doSomething(source)
}
Thanks.