code: private static boolean checkCollectionMembers(Collection<?> c, Class<?> type) {
          for (Object element : c) {
              if (element != null && !type.isInstance(element)) {
                  return false;
              }
          }
          return true;
      }
docs: Dynamically check that the members of the collection are all
  instances of the given type (or null).