1public static <E> void append(List<E> list, Class<E> cls) throws Exception {
2 E elem = cls.newInstance(); // OK
3 list.add(elem);
4}
5//You can invoke the append method as follows:
6List<String> ls = new ArrayList<>();
7append(ls, String.class);