public static <X> void checkCollection(Collection<X> elements, Class<X> viewedAs) {
		if (elements == null || viewedAs == null) {
			throw new NullPointerException();
		}
		
		if (!Serializable.class.isAssignableFrom(viewedAs)) {
			throw new InvalidProgramException("The elements are not serializable (java.io.Serializable).");
		}
		
		for (X elem : elements) {
			if (elem == null) {
				throw new IllegalArgumentException("The collection must not contain null elements.");
			}
			
			if (!viewedAs.isAssignableFrom(elem.getClass())) {
				throw new IllegalArgumentException("The elements in the collection are not all subclasses of " + 
							viewedAs.getCanonicalName());
			}
		}
	}
public static < X > void checkCollection ( Collection < X > elements , Class < X > viewedAs ) { if ( elements == null || viewedAs == null ) { throw new NullPointerException ( ) ; } if ( ! Serializable . class . isAssignableFrom ( viewedAs ) ) { throw new InvalidProgramException ( "The elements are not serializable (java.io.Serializable)." ) ; } for ( X elem : elements ) { if ( elem == null ) { throw new IllegalArgumentException ( "The collection must not contain null elements." ) ; } if ( ! viewedAs . isAssignableFrom ( elem . getClass ( ) ) ) { throw new IllegalArgumentException ( "The elements in the collection are not all subclasses of " + viewedAs . getCanonicalName ( ) ) ; } } }
--------------------------------------------------------------------------------------------