public static <OUT> void checkCollection(Collection<OUT> elements, Class<OUT> viewedAs) {
		for (OUT elem : elements) {
			if (elem == null) {
				throw new IllegalArgumentException("The collection contains a null element");
			}

			if (!viewedAs.isAssignableFrom(elem.getClass())) {
				throw new IllegalArgumentException("The elements in the collection are not all subclasses of " +
						viewedAs.getCanonicalName());
			}
		}
	}
public static < OUT > void checkCollection ( Collection < OUT > elements , Class < OUT > viewedAs ) { for ( OUT elem : elements ) { if ( elem == null ) { throw new IllegalArgumentException ( "The collection contains a null element" ) ; } if ( ! viewedAs . isAssignableFrom ( elem . getClass ( ) ) ) { throw new IllegalArgumentException ( "The elements in the collection are not all subclasses of " + viewedAs . getCanonicalName ( ) ) ; } } }
Verifies that all elements in the collection are non-null, and are of the given class, or
a subclass thereof.

@param elements The collection to check.
@param viewedAs The class to which the elements must be assignable to.

@param <OUT> The generic type of the collection to be checked.