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 .