【问题标题】:How call withLatestFrom() method (rxjava) from kotlin?如何从 kotlin 调用 withLatestFrom() 方法(rxjava)?
【发布时间】:2019-07-09 10:46:55
【问题描述】:

我看到方法 withLatestFrom() 的编译错误有什么问题?这是实验截图:

val source1 = Observable.just(1,2,3)
val source2 = Observable.just("A", "B", "C")

source1.withLatestFrom(source2) {
   intValue: Int, stringValue: String, stringResult: String -> 
   "Result string: $intValue $stringValue"} 

错误:不能使用提供的参数调用以下函数:

【问题讨论】:

    标签: android kotlin


    【解决方案1】:

    Kotlin 无法推断 lambda 是什么类型,请手动传递。

    source1.withLatestFrom(source2, BiFunction<Int, String, String> { intValue, stringValue -> "Result string: $intValue $stringValue" })
    

    【讨论】:

      猜你喜欢
      • 2019-05-10
      • 2017-11-12
      • 1970-01-01
      • 2022-12-10
      • 1970-01-01
      • 1970-01-01
      • 2018-06-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多