1

这是 Flowable.generate 失败的存根尝试(类型注释比我通常使用的要多):

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

应该为编译器提供什么?

4

1 回答 1

2

for 的类型generate()应该是<String, Int>,for 的类型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 ->  }
)
于 2017-10-16T05:08:30.050 回答