Netflix/RxJava — pull request #490 by samuelgruetter (2013-11-17 15:10:13+00:00)
Title: Scala Adaptor: Inheritance, subscriptions and subjects

I tried to add subscriptions and subjects using the value class trick, and came to the conclusion that it won't work. The problem is that inheritance and value classes don't work together, because value classes cannot be extended. We want Observable to be a value class, and at the same time, we want Subject to extend Observable, so that doesn't work.

This PR is very similar to [Erik's code](https://github.com/headinthebox/ScalaBindingsRecent), but I added a trait

```scala
trait JavaWrapper[+W] {
def asJava: W
}
```

which all classes extend. This allows us to have an `asJava` method everywhere (instead of `asJavaSubject` / `asJavaObserver` etc). The main challenge was to get the double inheritance Subject extends Observer and Observable working.
Now all wrappers are done the same way. For instance, Observable looks as follows:

```scala
trait Observable[+T] extends JavaWrapper[rx.Observable[_ <: T]] {
...
}

object Observable {
private[Observable] class ObservableWrapper[+T](val asJava: rx.Observable[_ <: T]) extends Observable[T] {}

def apply[T](asJava: rx.Observable[_ <: T]): Observable[T] = {
new ObservableWrapper[T](asJava)
}

...
}
```

In Scala code, to convert from Scala types to Java types, there's the `asJava` method, and to convert from Java types to Scala types, there's an `apply` method in each companion object.

When we used value classes, such conversions were not necessary in Java, because Scala types appeared as Java types for the Java compiler. Now, they become necessary, but note that this PR does not yet contain such conversions, but that should be no big problem.