gpt4 book ai didi

java - 如何使用 Kotlin 中的 Flowable.generate

转载 作者:行者123 更新时间:2023-11-30 02:21:12 25 4
gpt4 key购买 nike

这是 Flowable.generate 的失败 stub 尝试(带有比我通常使用的更多的类型注释):

val xs: Flowable<String> = Flowable.generate<Int, String>(
java.util.concurrent.Callable<Int> { -> 0 },
io.reactivex.functions.BiConsumer<Int, String> { t1, t2 -> }
)

我想使用的 Java 签名是:

public static <T, S> Flowable<T> generate(Callable<S> initialState, final BiConsumer<S, Emitter<T>> generator)

我收到的错误是:

Error:(145, 12) None of the following functions can be called with the arguments supplied:
@CheckReturnValue @BackpressureSupport @SchedulerSupport public final fun <T : Any!, S : Any!> generate(p0: (() -> (???..???))!, p1: (((???..???), Emitter<(???..???)>!) -> Unit)!): Flowable<(???..???)>! defined in io.reactivex.Flowable
@CheckReturnValue @BackpressureSupport @SchedulerSupport public final fun <T : Any!, S : Any!> generate(p0: (() -> (???..???))!, p1: ((???, Emitter<(???..???)>) -> ???)!): Flowable<(???..???)>! defined in io.reactivex.Flowable
@CheckReturnValue @BackpressureSupport @SchedulerSupport public open fun <T : Any!, S : Any!> generate(p0: Callable<(???..???)>!, p1: BiConsumer<(???..???), Emitter<String!>!>!): Flowable<String!>! defined in io.reactivex.Flowable
@CheckReturnValue @BackpressureSupport @SchedulerSupport public open fun <T : Any!, S : Any!> generate(p0: Callable<Int!>!, p1: BiFunction<Int!, Emitter<(???..???)>!, Int!>!): Flowable<(???..???)>! defined in io.reactivex.Flowable

我应该向编译器提供什么?

最佳答案

generate() 的类型应该是<String, Int>以及 BiConsumer 的类型应该是<Int, Emitter<String>> .

val xs: Flowable<String> = Flowable.generate<String, Int>(
java.util.concurrent.Callable<Int> { -> 0 },
io.reactivex.functions.BiConsumer<Int, Emitter<String>> { t1, t2 -> }
)

关于java - 如何使用 Kotlin 中的 Flowable.generate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46761401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com