Schadenfreude
03/08/2019, 4:53 PM// Java fun
fun <T:E> registerEvent(cls:Class<T>, consumer: Consumer<T>) : Disposable {
return this.listen(cls)
.subscribe(consumer)
}
// Kotlin fun (calls the java one)
inline fun <reified T:E> registerEvent(consumer: Consumer<T>): Disposable {
return registerEvent(T::class.java, consumer)
}
In java I have no problem calling registerEvernt(SomeClass.class, this::consumerMethod)
, but in Kotlin, when I try to do a method reference for the consumer, the compiler gives me an error and says it returns a KFunction1<SomeClass, Unit>
and the required parameter is Consumer<SomeClass>
. Is there any way I can make the functions behave the same, or is the inline
or something else making it impossible?skoric
03/08/2019, 6:06 PMKFunction1<>
skoric
03/08/2019, 6:07 PMskoric
03/08/2019, 6:08 PMval consumer = Consumer { ... }
Schadenfreude
03/11/2019, 8:36 AM(Consumer) -> Unit
as a consumer, but the subscribe method doesn’t have an override that accepts that… Oh well I guess I’ll have to live with it…