Here you can find the source of castList(Class extends T> clazz, Collection> collection)
Parameter | Description |
---|---|
T | the type of elements contained in the raw list. |
clazz | is the Class of the Collection entries. |
collection | is the raw Collection . |
public static <T> List<T> castList(Class<? extends T> clazz, Collection<?> collection)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { /**//from www .j ava 2 s . c o m * Casts a raw {@link Collection} to a generic {@link List}. Can be used to avoid type safety problems when dealing * with raw lists. * @param <T> the type of elements contained in the raw list. * @param clazz is the {@link Class} of the {@link Collection} entries. * @param collection is the raw {@link Collection}. * @return the generic {@link List}. */ public static <T> List<T> castList(Class<? extends T> clazz, Collection<?> collection) { List<T> genericList = new ArrayList<T>(collection.size()); for (Object object : collection) { genericList.add(clazz.cast(object)); } return genericList; } }