Java tutorial
//package com.java2s; import java.util.Collection; public class Main { public static void checkContent(final Collection<?> collection, final Class<?> clazz) { for (final Object o : collection) { if (!clazz.isInstance(o)) { throw new IllegalArgumentException( "Collection has an instance of " + o.getClass() + ", which doesn't inherit from " + clazz); } } } }