public static < T > Collection < Class < ? extends T > > getSubTypesOf ( Class < T > type , String ... packageNames ) { List < Class < ? extends T > > classes = getClasses ( packageNames ) . stream ( ) . filter ( aClass -> type . isAssignableFrom ( aClass ) ) . map ( aClass -> ( Class < ? extends T > ) aClass ) . collect ( Collectors . toList ( ) ) ; // TODO: pass a Supplier to toList() to avoid map return Collections . unmodifiableCollection ( classes ) ; }
Gets all sub types in hierarchy of a given type .