protected < T extends Listener > Collection < T > copyList ( Class < T > listenerClass , Stream < Object > listeners , int sizeHint ) { if ( sizeHint == 0 ) { return Collections . emptyList ( ) ; } return listeners . map ( listenerClass :: cast ) . collect ( Collectors . toCollection ( ( ) -> new ArrayList <> ( sizeHint ) ) ) ; }
Creates a collection from the given stream casting each object to the provided listener class . The returned collection must not necessarily be mutable .