Vladimir Tagakov
03/16/2022, 1:12 AMfun fact(): Observable<Any> = Observable.just(false)
.distinctUntilChanged() // fails compilation
vs
fun fact(): Observable<Any> = Observable.just(false)
//.distinctUntilChanged() // compiles just fine
xxfast
03/16/2022, 1:31 AMxxfast
03/16/2022, 1:31 AMpepos
03/16/2022, 1:33 AMObservable<Object> observable = Observable.just(true).distinctUntilChanged(); // does not compile
pepos
03/16/2022, 1:33 AMObservable<Object> observable = Observable.just(true); // compiles just fine
mkrussel
03/16/2022, 2:18 AMObservable<out T>
since that is not possible with Java. So Kotlin assumes that you can push things into the Observable.
With type inference happening fun fact(): Observable<Any> = Observable.just(false)
gets translated to fun fact(): Observable<Any> = Observable.just<Any>(false)
since false
is an any.
But that doesn't work once you call a method on it. Same thing happens with something like emptyList()
the type will be based on what it is getting assigned to, but if you do emptyList().toSet()
it will lose the ability to figure out the type and require you to specify it.gildor
03/16/2022, 2:30 AMephemient
03/16/2022, 3:17 AMxxfast
03/16/2022, 3:17 AMxxfast
03/16/2022, 3:18 AMVladimir Tagakov
03/16/2022, 3:22 AM