@SuppressWarnings("unchecked")
   public <T> ObjectInstantiator<T> getInstantiatorOf(Class<T> clazz) {
      if(clazz.isPrimitive()) {
         throw new IllegalArgumentException("Primitive types can't be instantiated in Java");
      }
      if(cache == null) {
         return strategy.newInstantiatorOf(clazz);
      }
      ObjectInstantiator<?> instantiator = cache.get(clazz.getName());
      if(instantiator == null) {
         ObjectInstantiator<?> newInstantiator = strategy.newInstantiatorOf(clazz);
         instantiator = cache.putIfAbsent(clazz.getName(), newInstantiator);
         if(instantiator == null) {
            instantiator = newInstantiator;
         }
      }
      return (ObjectInstantiator<T>) instantiator;
   }
@ SuppressWarnings ( "unchecked" ) public < T > ObjectInstantiator < T > getInstantiatorOf ( Class < T > clazz ) { if ( clazz . isPrimitive ( ) ) { throw new IllegalArgumentException ( "Primitive types can't be instantiated in Java" ) ; } if ( cache == null ) { return strategy . newInstantiatorOf ( clazz ) ; } ObjectInstantiator < ? > instantiator = cache . get ( clazz . getName ( ) ) ; if ( instantiator == null ) { ObjectInstantiator < ? > newInstantiator = strategy . newInstantiatorOf ( clazz ) ; instantiator = cache . putIfAbsent ( clazz . getName ( ) , newInstantiator ) ; if ( instantiator == null ) { instantiator = newInstantiator ; } } return ( ObjectInstantiator < T > ) instantiator ; }
Will pick the best instantiator for the provided class. If you need to create a lot of
instances from the same class, it is way more efficient to create them from the same
ObjectInstantiator than calling {@link #newInstance(Class)}.

@param clazz Class to instantiate
@return Instantiator dedicated to the class