Return an {@link ObjectInstantiator} allowing to create instance without any constructor being
called.

@param type Class to instantiate
@return The ObjectInstantiator for the class
504415
public <T> ObjectInstantiator<T> newInstantiatorOf(Class<T> type) {

      if(PlatformDescription.isThisJVM(HOTSPOT) || PlatformDescription.isThisJVM(OPENJDK)) {
         // Java 7 GAE was under a security manager so we use a degraded system
         if(PlatformDescription.isGoogleAppEngine() && PlatformDescription.SPECIFICATION_VERSION.equals("1.7")) {
            if(Serializable.class.isAssignableFrom(type)) {
               return new ObjectInputStreamInstantiator<>(type);
            }
            return new AccessibleInstantiator<>(type);
         }
         // The UnsafeFactoryInstantiator would also work. But according to benchmarks, it is 2.5
         // times slower. So I prefer to use this one
         return new SunReflectionFactoryInstantiator<>(type);
      }
      else if(PlatformDescription.isThisJVM(DALVIK)) {
         if(PlatformDescription.isAndroidOpenJDK()) {
            // Starting at Android N which is based on OpenJDK
            return new UnsafeFactoryInstantiator<>(type);
         }
         if(ANDROID_VERSION <= 10) {
            // Android 2.3 Gingerbread and lower
            return new Android10Instantiator<>(type);
         }
         if(ANDROID_VERSION <= 17) {
            // Android 3.0 Honeycomb to 4.2 Jelly Bean
            return new Android17Instantiator<>(type);
         }
         // Android 4.3 until Android N
         return new Android18Instantiator<>(type);
      }
      else if(PlatformDescription.isThisJVM(GNU)) {
         return new GCJInstantiator<>(type);
      }
      else if(PlatformDescription.isThisJVM(PERC)) {
         return new PercInstantiator<>(type);
      }

      // Fallback instantiator, should work with most modern JVM
      return new UnsafeFactoryInstantiator<>(type);

   }
679460
@SuppressWarnings({ "unchecked", "rawtypes" })
  public static <T> Option<Instantiator<T>> createInstantiator(
      Errors errors, Class<T> klass, InstantiatorModule... modules) {
    // we do not want to expose the covariant option
    return (Option) factoryFor(errors, klass, modules).build();
  }
431856
public <E> Optional<E> create(Class<E> type) {
    List<Constructor<?>> constructors = reflect().constructors()
        .filter(declared(Modifier.PUBLIC))
        .from(type);
    Optional created;
    for (Constructor<?> constructor : constructors) {
      created = tryCreate(constructor);
      if (created.isPresent()) {
        return created;
      }
    }
    return Optional.empty();
  }
598866
public static ConstructorRef create(TypeInfo type, Iterable<Type> argTypes) {
    return create(
        type, new Method("<init>", Type.VOID_TYPE, Iterables.toArray(argTypes, Type.class)));
  }
54012
public <T extends Annotation> T getAnnotation(Class<T> type) {
    return member.getAnnotation(type);
  }
617739
public static Optional<?> tryInstantiate(String name, ClassLoader classLoader) {
        try {
            return ClassUtils.forName(name, classLoader)
                .flatMap(InstantiationUtils::tryInstantiate);
        } catch (Throwable e) {
            Logger log = LoggerFactory.getLogger(InstantiationUtils.class);
            if (log.isDebugEnabled()) {
                log.debug("Tried, but could not instantiate type: " + name, e);
            }
            return Optional.empty();
        }
    }
756192
public static Object instantiate(String type, ClassLoader classLoader) {
        try {
            return ClassUtils.forName(type, classLoader)
                .flatMap(InstantiationUtils::tryInstantiate)
                .orElseThrow(() -> new InstantiationException("No class found for name: " + type));
        } catch (Throwable e) {
            throw new InstantiationException("Could not instantiate type [" + type + "]: " + e.getMessage(), e);
        }
    }
674327
public static <T> T instantiate(Class<T> type) {
        try {
            return BeanIntrospector.SHARED.findIntrospection(type).map(BeanIntrospection::instantiate).orElseGet(() -> {
                try {
                    Logger log = ClassUtils.REFLECTION_LOGGER;
                    if (log.isDebugEnabled()) {
                        log.debug("Reflectively instantiating type: " + type);
                    }
                    return type.newInstance();
                } catch (Throwable e) {
                    throw new InstantiationException("Could not instantiate type [" + type.getName() + "]: " + e.getMessage(), e);
                }
            });
        } catch (Throwable e) {
            throw new InstantiationException("Could not instantiate type [" + type.getName() + "]: " + e.getMessage(), e);
        }
    }
781446
public JBBPClassInstantiator make(final JBBPClassInstantiatorType type) {
    JBBPUtils.assertNotNull(type, "Type must not be null");

    String className = "com.igormaznitsa.jbbp.mapper.instantiators.JBBPSafeInstantiator";

    switch (type) {
      case AUTO: {
        final String customClassName = JBBPSystemProperty.PROPERTY_INSTANTIATOR_CLASS.getAsString(null);
        if (customClassName == null) {
          try {
            final Class<?> unsafeclazz = Class.forName("sun.misc.Unsafe");
            unsafeclazz.getDeclaredField("theUnsafe");
            className = "com.igormaznitsa.jbbp.mapper.instantiators.JBBPUnsafeInstantiator";
          } catch (ClassNotFoundException | NoSuchFieldException | SecurityException ex) {
            // do nothing
          }
        } else {
          className = customClassName;
        }
      }
      break;
      case SAFE: {
        className = "com.igormaznitsa.jbbp.mapper.instantiators.JBBPSafeInstantiator";
      }
      break;
      case UNSAFE: {
        className = "com.igormaznitsa.jbbp.mapper.instantiators.JBBPUnsafeInstantiator";
      }
      break;
      default:
        throw new Error("Unexpected type, contact developer! [" + type + ']');
    }

    return (JBBPClassInstantiator) ReflectUtils.newInstanceForClassName(className);
  }
329496
public Map<String, Object> getInitiator() {
        TreeMap<String, Object> map = new TreeMap<String, Object>();
        synchronized (eventMap) {
            for (Entry<String, Object> entry : eventMap.entrySet()) {
                if (entry.getKey().startsWith(INITIATOR))
                    map.put(entry.getKey(), entry.getValue());
            }
        }
        return map;
    }
1061778
public static CertificateFactory getCertificateFactory(String type) {
		final Provider provider = GlobalBouncyCastleProvider.INSTANCE.getProvider();

		CertificateFactory factory;
		try {
			factory = (null == provider) ? CertificateFactory.getInstance(type) : CertificateFactory.getInstance(type, provider);
		} catch (CertificateException e) {
			throw new CryptoException(e);
		}
		return factory;
	}
1123388
public static <T extends Annotation> T create(Class<T> annotationType) {
    return new Builder<T>(annotationType).create();
  }
598892
public static <T> Constructor<T> getConstructor(Class<T> instantiable, Class<?>... constructorParameterTypes)
    {
        try
        {
            return instantiable.getConstructor(constructorParameterTypes);
        }
        catch (NoSuchMethodException ignored)
        {
            return ReflectionHelper.searchForConstructor(instantiable, constructorParameterTypes);
        }
    }
1177456
@SuppressWarnings("WeakerAccess")
  public CreateInstanceRequest setType(@Nonnull Instance.Type type) {
    Preconditions.checkNotNull(type);
    Preconditions.checkArgument(type != Instance.Type.UNRECOGNIZED, "Type is unrecognized");
    builder.getInstanceBuilder().setType(type.toProto());
    return this;
  }
621654
private <T> Instantiator<T> getByDefaultConstructor(TypeToken<T> type) {
    try {
      final Constructor<? super T> defaultCons = type.getRawType().getDeclaredConstructor();
      defaultCons.setAccessible(true);

      return new Instantiator<T>() {
        @Override
        public T create() {
          try {
            return (T) defaultCons.newInstance();
          } catch (Exception e) {
            throw Throwables.propagate(e);
          }
        }
      };

    } catch (NoSuchMethodException e) {
      return null;
    }
  }
585428
public <A> BindStep<ConfigFactory, A> bind(final Class<A> type) {

        checkNotNull(type);

        return new BindStep<ConfigFactory, A>() {

            @Override
            public ConfigFactory toInstance(A instance) {

                return withBindings(
                    bindings.set(type, checkNotNull(instance))
                );
            }

            @Override
            public ConfigFactory toNothing() {

                return withBindings(
                    bindings.remove(type)
                );
            }
        };
    }
104805
protected Object createObject (Class type) throws InvocationTargetException {
		// Use deferred construction if a non-zero-arg constructor is available.
		DeferredConstruction deferredConstruction = Beans.getDeferredConstruction(type, config);
		if (deferredConstruction != null) return deferredConstruction;
		return Beans.createObject(type, config.privateConstructors);
	}