public static Class [ ] getClasses ( String basePackage , Class [ ] requiredInterfaces ) { List classes = new ArrayList ( ) ; ClassCriteria criteria = new ClassCriteria ( requiredInterfaces ) ; String basePath = basePackage . replace ( ' ' , File . separatorChar ) ; String [ ] resourcesNames = classpathResources . getResources ( basePath , criteria ) ; for ( int i = 0 ; i < resourcesNames . length ; i ++ ) { String resourceName = resourcesNames [ i ] ; if ( resourceName == null ) { continue ; } String className = getClassName ( resourceName ) ; try { Class c = Class . forName ( className ) ; classes . add ( c ) ; } catch ( ClassNotFoundException e ) { // This should not happen since we've already validated the class } } return ( Class [ ] ) classes . toArray ( new Class [ classes . size ( ) ] ) ; }
Returns an array of concrete classes in the given package that implement all of the specified interfaces .