If I have an extension function that takes in `(T)...
# announcements
a
If I have an extension function that takes in
(T) -> Unit
as a function type, how can I call this from Java? Does anyone have a code sample of this?
s
(T) -> null
? What type is null supposed to be here?
1
a
Flowable<T>.customSubscribeMethod(onNext: (T) -> Unit)
sorry misstyped null will edit
So I wanna do
RxUtilsKt.customSubscribeMethod(myFlowable, ???)
s
ahh gotcha
isn’t that just a
Consumer<T>
or am I misunderstanding you?
r
You would call it like any other lambda from Java (though you may have to return
Unit.INSTANCE
)
You should be able to do
RxUtilsKt.customSubscribeMethod(myFlowable, it -> { ... })
a
Hmm okay that's close but I'm getting incompatible parameter types
RxUtilsKt.doAfterDelay(Flowable.just(1), input -> Unit.INSTANCE);
s
what does it say it’s expecting?
a
The error doesn't say
got it
it was expecting a Kotlin
Funciton0<>
and when I wrote that the IDE let me rewrite as a lambda
RxUtilsKt.doAfterDelay(Flowable.just(1), 100, () -> Unit.INSTANCE);
🔥 1
Thanks! 🙂
s
Ahh good call @Ruckus
a
In hindsight, I should have just told my coworker to convert the class to Kotlin and we wouldn't stress LOL
Also @Ruckus Your snippet was right, I realize I messed with you by having one example of (T) -> Unit and one of () -> Unit I apologize for the inconsistency. 🙂
👍 1
Sometimes dumbing down your problems causes more trouble than it's worth, should have just posted the actual code haha.