问题描述:

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?

网友答案:

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.

相关阅读:
Top