castFrom<S, T> method Null safety

Queue<T> castFrom<S, T>(
  1. Queue<S> source
)
override

Adapts source to be a Queue<T>.

Any time the queue would produce an element that is not a T, the element access will throw.

Any time a T value is attempted stored into the adapted queue, the store will throw unless the value is also an instance of S.

If all accessed elements of source are actually instances of T, and if all elements stored into the returned queue are actually instance of S, then the returned queue can be used as a Queue<T>.

Methods like contains and remove which accept one Object? as argument, will pass the argument directly to the this queue's method without any checks.

Implementation

static Queue<T> castFrom<S, T>(Queue<S> source) => CastQueue<S, T>(source);