Here you can find the source of cast(Class
@SuppressWarnings("unchecked") public static <T> List<T> cast(Class<T> clazz, List<?> list)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { @SuppressWarnings("unchecked") public static <T> List<T> cast(Class<T> clazz, List<?> list) { ArrayList<T> castedList = new ArrayList<T>(); for (Object o : list) { castedList.add((T) o);/* w ww.j av a 2s. c om*/ } return castedList; } }