cloneSet<E> method

  1. @override
Set<E> cloneSet<E>(
  1. Set<E> source
)
override

Return a deep-cloned Set.

When doTypedClone is true the returned set preserves element types and performs typed cloning of elements. Typed cloning will throw UnsupportedTypedCloneException if a nested Map is encountered.

On dynamic cloning preserves the concrete Set implementation (e.g. LinkedHashSet, HashSet, UnmodifiableSetView). Typed nested cloning will erase generics at runtime; the typed Set cloning implementation relies on toSet() to preserve the runtime element type of the original set, but not underlying implementation.

Implementation

@override
Set<E> cloneSet<E>(Set<E> source) {
  if (_nestIndex > nestLimit) {
    throw LimitExceededException('depth', _nestIndex);
  }
  _nestIndex++;
  try {
    return super.cloneSet<E>(source);
  } finally {
    _nestIndex--;
  }
}