cast<T> method Null safety

QueueList<T> cast<T>()
inherited

Returns a view of this list as a list of R instances.

If this list contains only instances of R, all read operations will work correctly. If any operation tries to read an element that is not an instance of R, the access will throw instead.

Elements added to the list (e.g., by using add or addAll) must be instance of R to be valid arguments to the adding function, and they must be instances of E as well to be accepted by this list as well.

Methods like contains and remove which accept Object? as argument will pass the argument directly to the this list's method without any checks. That means that you can do listOfStrings.cast<int>().remove("a") successfully, even if it looks like it shouldn't have any effect.

Typically implemented as List.castFrom<E, R>(this).

Implementation

QueueList<T> cast<T>() {
  if (this is QueueList<T>) return this as QueueList<T>;
  throw UnsupportedError("$this cannot be cast to the desired type.");
}