public static < T > T loadInstanceOf ( String implClassName , Class < T > superClass , Class < ? > [ ] constructorTypes , Object [ ] constructorArgs ) { try { Class < ? extends T > configClass = loadClass ( implClassName , superClass ) ; Constructor < ? extends T > constructor = configClass . getConstructor ( constructorTypes ) ; return constructor . newInstance ( constructorArgs ) ; } catch ( NoSuchMethodException | InstantiationException | IllegalAccessException e ) { throw new IllegalArgumentException ( "No valid " + superClass + " binding exists" , e ) ; } catch ( InvocationTargetException ite ) { throw new IllegalStateException ( "Could not instantiate " + superClass + " due to exception" , ite . getCause ( ) ) ; } }
Loads and instantiates a named implementation class a subclass of a given supertype whose constructor takes the given arguments .