Here you can find the source of castList(Class extends T> clazz, Collection> c)
Parameter | Description |
---|---|
clazz | a parameter |
c | a parameter |
Parameter | Description |
---|---|
ClassCastException | an exception |
public static <T> List<T> castList(Class<? extends T> clazz, Collection<?> c) throws ClassCastException
//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 ww w. jav a 2 s .c o m*/ * This method verifies the content of a list. * * @param clazz * @param c * @return * @throws ClassCastException */ public static <T> List<T> castList(Class<? extends T> clazz, Collection<?> c) throws ClassCastException { List<T> r = new ArrayList<T>(c.size()); for (Object o : c) r.add(clazz.cast(o)); return r; } }