@ SuppressWarnings ( "unchecked" ) private static < T > T newRegisteredInstance ( Map < Class < ? > , Class < ? > > implementationsRegistry , Type interfaceType ) throws BugError { Class < ? > implementation = getImplementation ( implementationsRegistry , interfaceType ) ; try { return ( T ) implementation . newInstance ( ) ; } catch ( IllegalAccessException e ) { // illegal access exception is thrown if the class or its no-arguments constructor is not accessible // since we use well known JRE classes this condition may never meet throw new BugError ( e ) ; } catch ( InstantiationException e ) { // instantiation exception is thrown if class is abstract, interface, array, primitive or void // since we use well known JRE classes this condition may never meet throw new BugError ( e ) ; } }
Lookup implementation for requested interface into given registry and return a new instance of it .