private static < T > List < T > castList ( List < ? > list , Class < T > castTo ) { List < T > casted = new ArrayList < T > ( list . size ( ) ) ; for ( Object object : list ) { casted . add ( castTo . cast ( object ) ) ; } return Collections . unmodifiableList ( casted ) ; }
Casts all objects in the given list to the given class adding the casted objects to a new list .