@ SuppressWarnings ( "all" ) synchronized public static < T > Set < Class < ? extends T > > getNonAbstractSubClasses ( Class < T > parentClass , String ... packageNames ) { return getNonAbstractSubClassInfoSet ( parentClass , packageNames ) . stream ( ) . map ( classInfo -> { try { //Here we must use parentClass's classloader to make sure we are always using the same classloader. return ( Class < ? extends T > ) parentClass . getClassLoader ( ) . loadClass ( classInfo . getName ( ) ) ; } catch ( ClassNotFoundException e ) { SystemOutLogger . SINGLETON . error ( "Failed to load class " + classInfo . getName ( ) , e , "" ) ; System . exit ( Constant . SYSTEM_EXIT_CODE_FOR_SYS_INIT_ERROR ) ; //dead code return null ; } } ) . collect ( Collectors . toSet ( ) ) ; }
Scan classpath for all concrete subclasses of specified interface or class