cast<S> method Null safety

  1. @override
StreamChannel<S> cast<S>()
override

Returns a copy of this with the generic type coerced to S.

If any events emitted by stream aren't of type S, they're converted into TypeError events (CastError on some SDK versions). Similarly, if any events are added to sink that aren't of type S, a TypeError is thrown.

Implementation

@override
StreamChannel<S> cast<S>() => StreamChannel(
    stream.cast(), StreamController(sync: true)..stream.cast<T>().pipe(sink));