typed<E> method Null safety

  1. @Deprecated('Use set.cast<E> instead.')
Set<E> typed<E>(
  1. Set base
)
Deprecated('Use set.cast<E> instead.')">@Deprecated('Use set.cast<E> instead.')

Creates a wrapper that asserts the types of values in base.

This soundly converts a Set without a generic type to a Set<E> by asserting that its elements are instances of E whenever they're accessed. If they're not, it throws a CastError. Note that even if an operation throws a CastError, it may still mutate the underlying collection.

This forwards all operations to base, so any changes in base will be reflected in this. If base is already a Set<E>, it's returned unmodified.

Implementation

@Deprecated('Use set.cast<E> instead.')
static Set<E> typed<E>(Set base) => base.cast<E>();