class foo { static void fromArrayToCollection(T[] a, Collection c) { for (T o : a) { c.add(o); } } void demo() { String[] sa = new String[100]; Collection cs = new ArrayList(); fromArrayToCollection(sa, cs);// T inferred to be String Integer[] ia = new Integer[100]; Collection cn = new ArrayList(); fromArrayToCollection(ia, cn);// T inferred to be Number } }