how do I easily use kotlin method references with ...
# rx
a
how do I easily use kotlin method references with rxjava subscribes?
for example somehow this works
Copy code
myObservable.subscribe(myObject::myMethod, ::myErrorMethod)
yet somehow this does not
myObservable.subscribe(myObject::myMethod, Consumer<Throwable> { ... })
and I am forced to do something awkward like this
myObservable.subscribe(Consumer { myObject.myMethod(it) }, Consumer<Throwable> { ... })
g
This is limitation of current SAM and type inference in Kotlin, many of those will be fixed with new type inference system, for now you can use RxKotlin library, which provides Kotlin friendly extension functions to solve such issues (for this particular case they have nice subscribeBy extension, where you can just pass Kotlin lambdas instead of Java interface with SAM)
👁️ 1
l
Thanks all