Protected method to construct the target class reflectively from the
specified type by passing its constructor an instance of this builder.

@return Instance of target class created from this builder.
768818
protected T construct() {
        if (_targetConstructor.isPresent()) {
            return _targetConstructor.get().apply(this);
        }
        try {
            final Constructor<? extends T> constructor = _targetClass.get().getDeclaredConstructor(this.getClass());
            AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
                constructor.setAccessible(true);
                return null;
            });
            return constructor.newInstance(this);

        } catch (final NoSuchMethodException
                | SecurityException
                | InstantiationException
                | IllegalAccessException
                | IllegalArgumentException e) {
            throw new UnsupportedOperationException(
                    String.format(UNABLE_TO_CONSTRUCT_TARGET_CLASS, _targetClass),
                    e);
        } catch (final InvocationTargetException e) {
            // If the constructor of the class threw an exception, unwrap it and
            // rethrow it. If the constructor throws anything other than a
            // RuntimeException we wrap it.
            final Throwable cause = e.getCause();
            if (cause instanceof RuntimeException) {
                throw (RuntimeException) cause;
            }
            throw new UnsupportedOperationException(
                    String.format(UNABLE_TO_CONSTRUCT_TARGET_CLASS, _targetClass),
                    cause);
        }
    }
275377
@SuppressWarnings("deprecation")
	protected Object createObject(Class<?> targetClass) throws ReflectiveOperationException {
		Enhance en = targetClass.getAnnotation(Enhance.class);
		boolean enhance = (en != null ? en.value() : this.enhance);
		
		return enhance ? com.jfinal.aop.Enhancer.enhance(targetClass) : targetClass.newInstance();
	}
197164
public <S, D> TypeMap<S, D> getOrCreate(S source, Class<S> sourceType, Class<D> destinationType,
      String typeMapName, MappingEngineImpl engine) {
    return getOrCreate(source, sourceType, destinationType, typeMapName, null, null,
        engine);
  }
1186311
public T copy() {
        T copy = Instantiator.of(type).instantiate();
        return copyInto(copy);
    }
918237
protected T build() {
        final T instance;
        try {
            instance = build(connection(), maxContentLength(),
                                     isValidateHttpHeaders(), isPropagateSettings());
        } catch (Throwable t) {
            throw new IllegalStateException("failed to create a new InboundHttp2ToHttpAdapter", t);
        }
        connection.addListener(instance);
        return instance;
    }
601455
static <T> Pair<Boolean, T> constructViaConstructor(Class<T> type, String fromValue) {

		Constructor[] allConstructors = type.getDeclaredConstructors();
		for (Constructor ctor : allConstructors) {

			Class<?>[] pType = ctor.getParameterTypes();
			if (pType.length == 1) { // ok ... match ... might be possible to use

				try {

					for (Class primitive : SIMPLE_TYPE) {

						if (pType[0].isAssignableFrom(primitive)) {

							Object value = stringToPrimitiveType(fromValue, primitive);
							return new Pair(true, ctor.newInstance(value));
						}
					}
				}
				catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
					//continue; // try next one ... if any
					log.warn("Failed constructing: " + ctor, e);
				}
			}
		}

		return new Pair<>(false, null);
	}
79703
@SafeVarargs
    public static <T> Constructor<T> getDeclaredConstructor(final Class<T> cls, final Class<?>... parameterTypes) {
        Map<Class<?>[], Constructor<?>> constructorPool = classDeclaredConstructorPool.get(cls);
        Constructor<T> constructor = null;

        if (constructorPool != null) {
            constructor = (Constructor<T>) constructorPool.get(parameterTypes);
        }

        if (constructor == null) {
            try {
                constructor = cls.getDeclaredConstructor(parameterTypes);

                // SHOULD NOT set it true here.
                // constructor.setAccessible(true);
            } catch (NoSuchMethodException e) {
                // ignore.
            }

            if (constructor != null) {
                if (constructorPool == null) {
                    constructorPool = new ArrayHashMap<>(ConcurrentHashMap.class);
                    classDeclaredConstructorPool.put(cls, constructorPool);
                }

                constructorPool.put(parameterTypes.clone(), constructor);
            }
        }

        return constructor;
    }
738699
public Object createNewInstance(Class[] types, Object[] args)
    {
        try
        {
            Object result;
            // create an instance of the target class
            if (types != null)
            {
                result = ClassHelper.newInstance(getClassToServe(), types, args, true);
            }
            else
            {
                result = ClassHelper.newInstance(getClassToServe(), true);
            }
            // if defined in OJB.properties all instances are wrapped by an interceptor
            result = InterceptorFactory.getInstance().createInterceptorFor(result);
            return result;

        }
        catch (InstantiationException e)
        {
            getLogger().error("ConfigurableFactory can't instantiate class " +
                    getClassToServe() + buildArgumentString(types, args), e);
            throw new PersistenceBrokerException(e);
        }
        catch (IllegalAccessException e)
        {
            getLogger().error("ConfigurableFactory can't access constructor for class " +
                    getClassToServe() + buildArgumentString(types, args), e);
            throw new PersistenceBrokerException(e);
        }
        catch (Exception e)
        {
            getLogger().error("ConfigurableFactory instantiation failed for class " +
                    getClassToServe() + buildArgumentString(types, args), e);
            throw new PersistenceBrokerException(e);
        }
    }
777260
static <T> T getInstance(Class<T> clazz) {
        @SuppressWarnings("unchecked")
        final T casted = (T) instanceCache.computeIfAbsent(clazz, type -> {
            try {
                return getInstance0(clazz);
            } catch (Exception e) {
                throw new IllegalStateException("A class must have an accessible default constructor: " +
                                                clazz.getName(), e);
            }
        });
        return casted;
    }
758779
private Object initiateByConstructor(Class<?> targetClass, List<Object> objects) throws Exception {
        Constructor<?> constr = targetClass.getConstructor(getClassList(objects));
        return constr.newInstance(objects.toArray());
    }
1051455
public <T> JdbcMapperBuilder<T> newBuilder(final TypeReference<T> target) {
        return newBuilder(target.getType());
    }
485486
@SuppressWarnings("unchecked") public static <T> Reflecter<T> from(T target) {
		return Decisions.isClass().apply(target) 
		        ? (((Class<T>) target).isArray() 
		                ? (Reflecter<T>) from(ObjectArrays.newArray(((Class<T>) target).getComponentType(), 0)) 
		                        : from((Class<T>) target)) : new Reflecter<T>(target);
	}
34911
public <Instance> Instance createInstance(InvocationHandler invocationHandler, CompositeType compositeType) {
        Class<?>[] classes = compositeType.getClasses();
        Constructor<?> constructor = classCache.getIfPresent(compositeType);
        if (constructor == null) {
            Class<?> type;
            try {
                type = Proxy.getProxyClass(classLoader, classes);
            } catch (IllegalArgumentException e) {
                throw new XOException("Cannot create proxy for " + compositeType + " of classes " + compositeType.getClasses(), e);
            }
            try {
                constructor = type.getConstructor(new Class<?>[] { InvocationHandler.class });
            } catch (NoSuchMethodException e) {
                throw new XOException("Cannot find constructor for " + compositeType, e);
            }
            classCache.put(compositeType, constructor);
        }
        Instance instance;
        try {
            instance = (Instance) constructor.newInstance(invocationHandler);
        } catch (Exception e) {
            throw new XOException("Cannot create instance of  " + compositeType, e);
        }
        return interceptorFactory.addInterceptor(instance, classes);
    }
91504
public <T> JdbcMapperBuilder<T> newBuilder(final Type target) {
		ClassMeta<T> classMeta = getClassMeta(target);
		return newBuilder(classMeta);
	}
803531
public static ConstructorBuilder getInstance(Context context,
            ClassDoc classDoc, ConstructorWriter writer) {
        return new ConstructorBuilder(context, classDoc, writer);
    }
850315
public Reflector create(Object... args) throws ReflectException {
        Class<?>[] types = getTypes(args);

        try {
            Constructor<?> constructor = type().getDeclaredConstructor(types);
            return with(constructor, args);
        } catch (NoSuchMethodException e) {
            for (Constructor<?> constructor : type().getDeclaredConstructors()) {
                if (match(constructor.getParameterTypes(), types)) {
                    return with(constructor, args);
                }
            }

            throw new ReflectException(e);
        }
    }
567385
public static ClassBuilder getInstance(Context context,
            TypeElement typeElement, ClassWriter writer) {
        return new ClassBuilder(context, typeElement, writer);
    }