我正在尝试开始使用 RxJava2、RxScala 和 Android。我在网上找到了一个小例子,我试图将其翻译成 Scala。但是 Scala 编译器无法确定这里的类型:
MainIntent.scala:7:missing parameter type
[error] actions("Button").subscribe(s => mainModel.resetText())
我也不确定这里需要什么类型。一个Flowable[_ <: Any]]
?我怎样才能让它工作?
这是代码:
import io.reactivex.functions.Consumer
import io.reactivex.Flowable
trait MainView {
def getActions: Map[String, Flowable[_ <: Any]]
def getConsumers: Map[String, Consumer[String]]
}
class MainIntent(mainView: MainView) {
lazy val actions: Map[String, Flowable[_ <: Any]] = mainView.getActions
lazy val mainModel = MainModel(mainView.getConsumers)
def start(): Unit = {
actions("Button").subscribe(s => mainModel.resetText())
actions("EditText").subscribe(changedText => mainModel.changeText(changedText.toString))
}
}
class MainActivity extends AppCompatActivity with MainView with TypedFindView {
...
override def onCreate(savedInstanceState: Bundle): Unit = {
...
new MainIntent(this).start()
}
def getActions(): Map[String, Flowable[_ <: Any]] = {
Map("Button" -> RxView.clicks(button).toFlowable(BackpressureStrategy.DROP),
"EditText" -> RxTextView.textChanges(editText).toFlowable(BackpressureStrategy.DROP))
}
...
}