@ SuppressWarnings ( "unchecked" ) public static < T > T createInstance ( Class < T > clazz ) { if ( clazz . isInterface ( ) ) { if ( clazz == List . class ) { return ( T ) new ArrayList ( ) ; } else if ( clazz == Map . class ) { return ( T ) new HashMap ( ) ; } throw new UnsupportedOperationException ( "Interface types can not be instantiated." ) ; } ObjectInstantiator instantiator = OBJENESIS . getInstantiatorOf ( clazz ) ; return ( T ) instantiator . newInstance ( ) ; }
Takes a class type and constructs it . If the class does not have an empty constructor this will find the parametrized constructor and use nulls and default values to construct the class .