/** * Call the class constructor with the given arguments * * @param c The class * @param args The arguments * @return The constructed object */ public static Object callConstructor(final Class<?> c, final Class<?>[] argTypes, final Object[] args) { try { final Constructor<?> cons = c.getConstructor(argTypes); return cons.newInstance(args); } catch (final InvocationTargetException e) { throw getCause(e); } catch (final IllegalAccessException e) { throw new IllegalStateException(e); } catch (final NoSuchMethodException e) { throw new IllegalStateException(e); } catch (final InstantiationException e) { throw new IllegalStateException(e); } }
public static Object callConstructor(final Class<?> c, final Class<?>[] argTypes, final Object[] args) { try { final Constructor<?> cons = c.getConstructor(argTypes); return cons.newInstance(args); } catch (final InvocationTargetException e) { throw getCause(e); } catch (final IllegalAccessException e) { throw new IllegalStateException(e); } catch (final NoSuchMethodException e) { throw new IllegalStateException(e); } catch (final InstantiationException e) { throw new IllegalStateException(e); } }
/** * Call the class constructor with the given arguments * * @param c The class * @param args The arguments * @return The constructed object */ public static Object callConstructor(Class<?> c, Class<?>[] argTypes, Object[] args) { try { Constructor<?> cons = c.getConstructor(argTypes); return cons.newInstance(args); } catch(InvocationTargetException e) { throw getCause(e); } catch(IllegalAccessException e) { throw new IllegalStateException(e); } catch(NoSuchMethodException e) { throw new IllegalStateException(e); } catch(InstantiationException e) { throw new IllegalStateException(e); } }