Reputation: 3592
I am trying to zip
two observables together.First is of type Single<SomeClass>
and second is Observable<SomeOtherClass>
. However, in .zip()
function the return types does not get cast to correct classes, I get raw types (T1
,T2
). Example:
Single<SomeClass> o1 = ....
Observable<SomeOtherClass> o2 = ....
Observable.zip(o1,o2, (u,u2) -> ...) // here I get 2 raw types
And if I try this way (since I am "zipping" 2 observables only):
o1.zipWith(o2, (someClass, u) -> ...) //here only o1 is cast to class instance
If I try Observable.zip(Observable.range(...),Observable.interval(...), (integer,long) -> ...)
I get the correct casts.
I can't figure out why it won't cast to my class objects in my example above, any suggestions?
Upvotes: 0
Views: 224
Reputation: 161
Using zip() you get a few objects in input, and transform them to something different in OUT. So you need to specify some output type:
Observable.zip(o1, o2, (u1,u2) -> new NewOtherClass(u1, u2))
In the example above the compiler know that return type for your lambda is NewOtherClass
.
Note, that Single and Observable can't be used in the same chain with no additional transformation (note .toObservable()
below):
Observable.zip(o1.toObservable(), o2, (u1,u2) -> /*return do something*/)
Upvotes: 1