Here you can find the source of castNonNullListParameterTo(String parameterName, List
public static <T, R extends T> List<R> castNonNullListParameterTo(String parameterName, List<T> value, Class<R> requiredType)
//package com.java2s; /***************************************************************************************** * *** BEGIN LICENSE BLOCK *****//www. java2 s .c om * * Version: MPL 2.0 * * echocat RedPrecursor, Copyright (c) 2011-2012 echocat * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * *** END LICENSE BLOCK ***** ****************************************************************************************/ import java.util.List; public class Main { public static <T, R extends T> List<R> castNonNullListParameterTo(String parameterName, List<T> value, Class<R> requiredType) { if (value == null) { throw new IllegalArgumentException(parameterName + " is null"); } for (T entry : value) { if (entry == null) { throw new IllegalArgumentException("One entry of " + parameterName + " is null."); } if (!requiredType.isInstance(entry)) { throw new IllegalArgumentException( "One entry of " + parameterName + " is not of type " + requiredType.getName() + "."); } } //noinspection unchecked return (List<R>) value; } }