mana February 2016

Converting RxJava to RxScala

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?

Answers


Samuel Gruetter February 2016

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.

Post Status

Asked in February 2016
Viewed 1,754 times
Voted 4
Answered 1 times

Search




Leave an answer