Converting RxJava to RxScala

感情迁移 提交于 2019-12-23 12:53:17

问题


Is there a way to use both RxJava and RxScala in one project?

import rx.lang.scala.{Observable => ScalaObservable}
import rx.{Observable => JavaObservable}

We have a module written in Java that is using the JavaObservable (RxJava). And then we have a Scala module that is supposed to use the Java module but is written in Scala.

Are there convenient methods to transform these into the other?


回答1:


Yes, this is possible by using the conversion functions such as toJavaObservable, toScalaObservable, etc in rx.lang.scala.JavaConversions.

You can either write the conversion explicitly (eg toJavaObservable(myScalaObservable), or if you enable implicit conversions and import rx.lang.scala.JavaConversions._, they will be inserted automatically by the compiler whenever a Java Observable is expected, but a Scala Observable is found, and vice versa.



来源:https://stackoverflow.com/questions/35264748/converting-rxjava-to-rxscala

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!