public T build ( ) throws IOException { check ( handler != null , "handler == null" ) ; check ( constructorArgTypes . length == constructorArgValues . length , "constructorArgValues.length != constructorArgTypes.length" ) ; Class < ? extends T > proxyClass = buildProxyClass ( ) ; Constructor < ? extends T > constructor ; try { constructor = proxyClass . getConstructor ( constructorArgTypes ) ; } catch ( NoSuchMethodException e ) { throw new IllegalArgumentException ( "No constructor for " + baseClass . getName ( ) + " with parameter types " + Arrays . toString ( constructorArgTypes ) ) ; } T result ; try { result = constructor . newInstance ( constructorArgValues ) ; } catch ( InstantiationException e ) { // Should not be thrown, generated class is not abstract. throw new AssertionError ( e ) ; } catch ( IllegalAccessException e ) { // Should not be thrown, the generated constructor is accessible. throw new AssertionError ( e ) ; } catch ( InvocationTargetException e ) { // Thrown when the base class constructor throws an exception. throw launderCause ( e ) ; } setInvocationHandler ( result , handler ) ; return result ; }
Create a new instance of the class to proxy .