public static < T > T createNewClassInstance ( Class < T > cls , Class < ? > [ ] ctorClassArgs , Object [ ] ctorArgs ) { try { if ( ctorClassArgs == null ) { return cls . newInstance ( ) ; } Constructor < T > ctor = cls . getConstructor ( ctorClassArgs ) ; return ctor . newInstance ( ctorArgs ) ; } catch ( InvocationTargetException e ) { throw new RuntimeException ( e . getCause ( ) ) ; } catch ( ReflectiveOperationException e ) { throw new RuntimeException ( e ) ; } }
Creates new instance of a class by calling a constructor that receives ctorClassArgs arguments .