Here you can find the source of getElementClass(Collection
@SuppressWarnings("unchecked") public static <E> Class<E> getElementClass(Collection<E> collection)
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { @SuppressWarnings("unchecked") public static <E> Class<E> getElementClass(Collection<E> collection) { final E nonNull = firstNonNull(collection); return nonNull == null ? null : (Class<E>) nonNull.getClass(); }//w ww .ja v a 2 s . c o m public static <E> E firstNonNull(Collection<E> collection) { return firstNonNull(collection, null); } public static <E> E firstNonNull(Collection<E> collection, E defaultValue) { for (E element : collection) { if (element != null) { return element; } } return defaultValue; } }