Casting to any type is safe because the set will never hold any elements.
434731
@SuppressWarnings("unchecked")
  public static <K, V> ImmutableSortedMap<K, V> of() {
    return EmptyImmutableSortedMap.forComparator(NATURAL_ORDER);
  }
678844
public static boolean shouldAutoCastTo(PrimitiveType from, PrimitiveType to) {
		InternalType[] castTypes = POSSIBLE_CAST_MAP.get(from);
		if (castTypes != null) {
			for (InternalType type : POSSIBLE_CAST_MAP.get(from)) {
				if (type.equals(to)) {
					return true;
				}
			}
		}
		return false;
	}
1317794
public boolean isNullable() {
    return members.stream().anyMatch(t -> t.getKind() == SoyType.Kind.NULL);
  }
1184621
public static <E, S extends Set<E>> UnmodifiableMutableSet<E> of(S set)
    {
        if (set == null)
        {
            throw new IllegalArgumentException("cannot create an UnmodifiableMutableSet for null");
        }
        return new UnmodifiableMutableSet<E>(SetAdapter.adapt(set));
    }
670139
@SuppressWarnings("unchecked")
    protected <T> Collection<T> castCollectionToType(Class collectionType, Collection<T> converted) throws ConversionException {
        if (!Collection.class.isAssignableFrom(collectionType)) {
            throw new ConversionException("Collection type should extends collection" + collectionType);
        }

        if (collectionType.isInterface()) {
            if (collectionType.isAssignableFrom(Set.class)) {
                return Collections.unmodifiableSet(new HashSet<>(converted));
            }
            if (collectionType.isAssignableFrom(List.class)) {
                return Collections.unmodifiableList(new LinkedList<>(converted));
            }
            if (collectionType.isAssignableFrom(Collection.class)) {
                return Collections.unmodifiableCollection(converted);
            }
            throw new ConversionException("Unsupported collection type " + collectionType);
        }
        try {
            Constructor constructor = collectionType.getConstructor(Collection.class);
            return (Collection<T>) constructor.newInstance(converted);
        } catch (Exception e) {
            throw new ConversionException("Could not create an instance of " + collectionType, e);
        }
    }
1207998
def valid_anytype(val):
    
    for validator in VALIDATOR.values():
        if validator == valid_anytype:  # To hinder recursion
            continue
        try:
            if validator(val):
                return True
        except NotValid:
            pass

    if isinstance(val, type):
        return True

    raise NotValid("AnyType")
1255003
public static <T> Iterable<T> nullSafeIterable(T[] iterable) {
        return (iterable != null) ? Arrays.asList(iterable) : Collections.EMPTY_LIST;
    }
708753
public static <E> List<E> copyOf(Iterable<? extends E> elements) {
    Preconditions.checkNotNull(elements, "elements");
    List<E> result = (elements instanceof Collection)
        // can pre-allocate the array
        ? new ArrayList<>(cast(elements).size())
        // cannot
        : new ArrayList<>();
    for (E e : elements) {
      result.add(e);
    }
    return Collections.unmodifiableList(result);
  }
449938
public static <T> SortedSet<T> asImmutable(SortedSet<T> self) {
        return Collections.unmodifiableSortedSet(self);
    }
570535
private static boolean isImmutableType(Object thing) {
    return ((thing == null)
        || (thing instanceof String)
        || (thing instanceof Integer)
        || (thing instanceof Long));
  }
453351
public static <T> Iterable<T> nullSafeIterable(Iterable<T> iterable) {
        return (iterable != null) ? iterable : Collections.EMPTY_LIST;
    }
1186522
function set(i, item, array)
{
	if (i < 0 || length(array) <= i)
	{
		return array;
	}
	return unsafeSet(i, item, array);
}
211670
static boolean equalsImpl(Set<?> s, @Nullable Object object) {
    if (s == object) {
      return true;
    }
    if (object instanceof Set) {
      Set<?> o = (Set<?>) object;

      try {
        return s.size() == o.size() && s.containsAll(o);
      } catch (NullPointerException ignored) {
        return false;
      } catch (ClassCastException ignored) {
        return false;
      }
    }
    return false;
  }
701365
public static <T> Iterable<T> cast(Iterable<?> iterable) {
    return iterable == null ? null : new CastingIterable<T>(iterable);
  }
1031931
public boolean retainAll(IntCollection ints) {
        IntIterator it = iterator();
        boolean changed = false;
        while (it.hasNext()) {
            if (!ints.contains(it.nextInt())) {
                it.remove();
                changed = true;
            }
        }
        return changed;
    }
1099761
public static <T> Set<T> toImmutableSet(final Set<? extends T> set) {
    switch (set.size()) {
      case 0:
        return Collections.emptySet();
      case 1:
        return Collections.singleton(set.iterator().next());
      default:
        return Collections.unmodifiableSet(set);
    }
  }
120907
def is_castable(src, dst):
    
    if ((src in [int, bool]) or rdltypes.is_user_enum(src)) and (dst in [int, bool]):
        # Pure numeric or enum can be cast to a numeric
        return True
    elif (src == rdltypes.ArrayPlaceholder) and (dst == rdltypes.ArrayPlaceholder):
        # Check that array element types also match
        if src.element_type is None:
            # indeterminate array type. Is castable
            return True
        elif src.element_type == dst.element_type:
            return True
        else:
            return False
    elif rdltypes.is_user_struct(dst):
        # Structs can be assigned their derived counterparts - aka their subclasses
        return issubclass(src, dst)
    elif dst == rdltypes.PropertyReference:
        return issubclass(src, rdltypes.PropertyReference)
    elif src == dst:
        return True
    else:
        return False