constructor.setAccessible(true); try { constructor.newInstance(); } catch (Exception e) { throw new IllegalStateException("invoking constructor failed.", e);
invoke.
try { return constructor.newInstance(args); } catch (InstantiationException e) { throw e.getCause();
try { return constructor.newInstance(args); } catch (InstantiationException e) { throw e.getCause();
if (clazz == null) throw new IllegalArgumentException("Class cannot be null!"); if (paramTypes == null) throw new IllegalArgumentException("ParamTypes cannot be null"); if (params == null) throw new IllegalArgumentException("Params cannot be null!"); final Constructor constructor = clazz.getDeclaredConstructor(paramTypes); constructor.setAccessible(true); ...
try { Constructor constructor = clazz.getConstructor(convertToMethodParameters(parameters)); return constructor.newInstance(parameters); } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); return null;
Object result = null; Constructor<?> constructor; try { constructor = objectClass.getDeclaredConstructor(classes); } catch (Exception e) { throw new RuntimeException( "Exception obtaining the constructor for class '" + objectClass + "' with params=" + params, e); boolean accessible = constructor.isAccessible(); constructor.setAccessible(true); try { result = constructor.newInstance(params); } catch (Exception e) { throw new RuntimeException( "Exception invoking the constructor for class '" + objectClass + "' with params=" + params, e); } finally { constructor.setAccessible(accessible); return result;
Constructor<T> constructor = clazz.getConstructor(argTypes);
return constructor.newInstance(args);
try { Constructor<T> constructor = cls.getDeclaredConstructor(); constructor.setAccessible(true); return constructor.newInstance(); } catch (Exception ignored) { return null;
return invokeConstructor(type, value, value.getClass());
try { return constructor.newInstance(arguments); } catch (Exception e) { throw new IllegalStateException("constructor invocation error", e);