Skip to content

Commit 2f8da39

Browse files
committed
Avoid the cast in toSet and toBuffer
1 parent a5900e4 commit 2f8da39

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/Observable.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4099,8 +4099,10 @@ trait Observable[+T]
40994099
* @return an Observable that emits a single item, a `Buffer` containing all of the items emitted by
41004100
* the source Observable.
41014101
*/
4102-
def toBuffer[U >: T]: Observable[mutable.Buffer[U]] = // use U >: T because Buffer is invariant
4103-
to[ArrayBuffer].asInstanceOf[Observable[mutable.Buffer[U]]]
4102+
def toBuffer[U >: T]: Observable[mutable.Buffer[U]] = { // use U >: T because Buffer is invariant
4103+
val us: Observable[U] = this
4104+
us.to[ArrayBuffer]
4105+
}
41044106

41054107
/**
41064108
* Returns an Observable that emits a single item, a `Set` composed of all the items emitted by
@@ -4112,8 +4114,10 @@ trait Observable[+T]
41124114
* @return an Observable that emits a single item, a `Set` containing all of the items emitted by
41134115
* the source Observable.
41144116
*/
4115-
def toSet[U >: T]: Observable[immutable.Set[U]] = // use U >: T because Set is invariant
4116-
to[immutable.Set].asInstanceOf[Observable[immutable.Set[U]]]
4117+
def toSet[U >: T]: Observable[immutable.Set[U]] = { // use U >: T because Set is invariant
4118+
val us: Observable[U] = this
4119+
us.to[immutable.Set]
4120+
}
41174121

41184122
/**
41194123
* Returns an Observable that emits a single item, an `Array` composed of all the items emitted by
@@ -4125,7 +4129,7 @@ trait Observable[+T]
41254129
* @return an Observable that emits a single item, an `Array` containing all of the items emitted by
41264130
* the source Observable.
41274131
*/
4128-
def toArray[U >: T : ClassTag]: Observable[Array[U]] = // use U >: T because Set is invariant
4132+
def toArray[U >: T : ClassTag]: Observable[Array[U]] = // use U >: T because Array is invariant
41294133
toBuffer[U].map(_.toArray)
41304134
}
41314135

0 commit comments

Comments
 (0)