parameterTypes[i] = args[i].getClass(); return invokeConstructor(klass, args, parameterTypes);
/** * Returns a constructor with single argument. * @param <T> the type of the constructor * @param klass the class to be constructed * @param parameterType The constructor parameter type * @return null if matching accessible constructor can not be found. * @see Class#getConstructor * @see #getAccessibleConstructor(java.lang.reflect.Constructor) */ public static <T> Constructor<T> getAccessibleConstructor( final Class<T> klass, final Class<?> parameterType) { final Class<?>[] parameterTypes = { parameterType }; return getAccessibleConstructor(klass, parameterTypes); }
parameterTypes[i] = args[i].getClass(); return invokeExactConstructor(klass, args, parameterTypes);
/** * <p>Convenience method returning new instance of <code>klazz</code> using a single argument constructor. * The formal parameter type is inferred from the actual values of <code>arg</code>. * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.</p> * * <p>The signatures should match exactly.</p> * * @param <T> the type of the object to be constructed * @param klass the class to be constructed. * @param arg the actual argument. May be null (this will result in calling the default constructor). * @return new instance of <code>klazz</code> * * @throws NoSuchMethodException If the constructor cannot be found * @throws IllegalAccessException If an error occurs accessing the constructor * @throws InvocationTargetException If an error occurs invoking the constructor * @throws InstantiationException If an error occurs instantiating the class * * @see #invokeExactConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[]) */ public static <T> T invokeExactConstructor(final Class<T> klass, final Object arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { final Object[] args = toArray(arg); return invokeExactConstructor(klass, args); }
/** * <p>Convenience method returning new instance of <code>klazz</code> using a single argument constructor. * The formal parameter type is inferred from the actual values of <code>arg</code>. * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.</p> * * <p>The signatures should be assignment compatible.</p> * * @param <T> the type of the object to be constructed * @param klass the class to be constructed. * @param arg the actual argument. May be null (this will result in calling the default constructor). * @return new instance of <code>klazz</code> * * @throws NoSuchMethodException If the constructor cannot be found * @throws IllegalAccessException If an error occurs accessing the constructor * @throws InvocationTargetException If an error occurs invoking the constructor * @throws InstantiationException If an error occurs instantiating the class * * @see #invokeConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[]) */ public static <T> T invokeConstructor(final Class<T> klass, final Object arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { final Object[] args = toArray(arg); return invokeConstructor(klass, args); }
getMatchingAccessibleConstructor(klass, parameterTypes); if (null == ctor) { throw new NoSuchMethodException( final Constructor<T> ctor = getAccessibleConstructor(klass, parameterTypes); if (null == ctor) { throw new NoSuchMethodException(
if(self.getBoolean("exact")){ if(paramTypes == null){ return ConstructorUtils.invokeExactConstructor(cls, args); }else{ return ConstructorUtils.invokeExactConstructor(cls, args, paramTypes); return ConstructorUtils.invokeConstructor(cls, args); }else{ return ConstructorUtils.invokeConstructor(cls, args, paramTypes);
/** * <p>Convenience method returning new instance of <code>klazz</code> using a single argument constructor. * The formal parameter type is inferred from the actual values of <code>arg</code>. * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.</p> * * <p>The signatures should be assignment compatible.</p> * * @param <T> the type of the object to be constructed * @param klass the class to be constructed. * @param arg the actual argument. May be null (this will result in calling the default constructor). * @return new instance of <code>klazz</code> * * @throws NoSuchMethodException If the constructor cannot be found * @throws IllegalAccessException If an error occurs accessing the constructor * @throws InvocationTargetException If an error occurs invoking the constructor * @throws InstantiationException If an error occurs instantiating the class * * @see #invokeConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[]) */ public static <T> T invokeConstructor(final Class<T> klass, final Object arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { final Object[] args = toArray(arg); return invokeConstructor(klass, args); }
getMatchingAccessibleConstructor(klass, parameterTypes); if (null == ctor) { throw new NoSuchMethodException( final Constructor<T> ctor = getAccessibleConstructor(klass, parameterTypes); if (null == ctor) { throw new NoSuchMethodException(
/** * <p>Convenience method returning new instance of <code>klazz</code> using a single argument constructor. * The formal parameter type is inferred from the actual values of <code>arg</code>. * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.</p> * * <p>The signatures should match exactly.</p> * * @param <T> the type of the object to be constructed * @param klass the class to be constructed. * @param arg the actual argument. May be null (this will result in calling the default constructor). * @return new instance of <code>klazz</code> * * @throws NoSuchMethodException If the constructor cannot be found * @throws IllegalAccessException If an error occurs accessing the constructor * @throws InvocationTargetException If an error occurs invoking the constructor * @throws InstantiationException If an error occurs instantiating the class * * @see #invokeExactConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[]) */ public static <T> T invokeExactConstructor(final Class<T> klass, final Object arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { final Object[] args = toArray(arg); return invokeExactConstructor(klass, args); }
parameterTypes[i] = args[i].getClass(); return invokeConstructor(klass, args, parameterTypes);
/** * <p>Convenience method returning new instance of <code>klazz</code> using a single argument constructor. * The formal parameter type is inferred from the actual values of <code>arg</code>. * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.</p> * * <p>The signatures should be assignment compatible.</p> * * @param <T> the type of the object to be constructed * @param klass the class to be constructed. * @param arg the actual argument. May be null (this will result in calling the default constructor). * @return new instance of <code>klazz</code> * * @throws NoSuchMethodException If the constructor cannot be found * @throws IllegalAccessException If an error occurs accessing the constructor * @throws InvocationTargetException If an error occurs invoking the constructor * @throws InstantiationException If an error occurs instantiating the class * * @see #invokeConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[]) */ public static <T> T invokeConstructor(final Class<T> klass, final Object arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { final Object[] args = toArray(arg); return invokeConstructor(klass, args); }
/** * Returns a constructor with single argument. * @param <T> the type of the constructor * @param klass the class to be constructed * @param parameterType The constructor parameter type * @return null if matching accessible constructor can not be found. * @see Class#getConstructor * @see #getAccessibleConstructor(java.lang.reflect.Constructor) */ public static <T> Constructor<T> getAccessibleConstructor( final Class<T> klass, final Class<?> parameterType) { final Class<?>[] parameterTypes = { parameterType }; return getAccessibleConstructor(klass, parameterTypes); }
getMatchingAccessibleConstructor(klass, parameterTypes); if (null == ctor) { throw new NoSuchMethodException( Constructor ctor = getAccessibleConstructor(klass, parameterTypes); if (null == ctor) { throw new NoSuchMethodException(
parameterTypes[i] = args[i].getClass(); return invokeExactConstructor(klass, args, parameterTypes);
/** * <p>Convenience method returning new instance of <code>klazz</code> using a single argument constructor. * The formal parameter type is inferred from the actual values of <code>arg</code>. * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.</p> * * <p>The signatures should match exactly.</p> * * @param <T> the type of the object to be constructed * @param klass the class to be constructed. * @param arg the actual argument. May be null (this will result in calling the default constructor). * @return new instance of <code>klazz</code> * * @throws NoSuchMethodException If the constructor cannot be found * @throws IllegalAccessException If an error occurs accessing the constructor * @throws InvocationTargetException If an error occurs invoking the constructor * @throws InstantiationException If an error occurs instantiating the class * * @see #invokeExactConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[]) */ public static <T> T invokeExactConstructor(final Class<T> klass, final Object arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { final Object[] args = toArray(arg); return invokeExactConstructor(klass, args); }
returnValue = invokeEnumInit(mState, (String) args[0], vm.getClassLoader()); } else { returnValue = ConstructorUtils.invokeConstructor(klazz, args);
/** * Returns a constructor given a class and signature. * @param <T> the type to be constructed * @param klass the class to be constructed * @param parameterTypes the parameter array * @return null if matching accessible constructor can not be found * @see Class#getConstructor * @see #getAccessibleConstructor(java.lang.reflect.Constructor) */ public static <T> Constructor<T> getAccessibleConstructor( final Class<T> klass, final Class<?>[] parameterTypes) { try { return getAccessibleConstructor( klass.getConstructor(parameterTypes)); } catch (final NoSuchMethodException e) { return (null); } }
getMatchingAccessibleConstructor(klass, parameterTypes); if (null == ctor) { throw new NoSuchMethodException( final Constructor<T> ctor = getAccessibleConstructor(klass, parameterTypes); if (null == ctor) { throw new NoSuchMethodException(
/** * <p>Convenience method returning new instance of <code>klazz</code> using a single argument constructor. * The formal parameter type is inferred from the actual values of <code>arg</code>. * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.</p> * * <p>The signatures should match exactly.</p> * * @param klass the class to be constructed. * @param arg the actual argument * @return new instance of <code>klazz</code> * * @throws NoSuchMethodException If the constructor cannot be found * @throws IllegalAccessException If an error occurs accessing the constructor * @throws InvocationTargetException If an error occurs invoking the constructor * @throws InstantiationException If an error occurs instantiating the class * * @see #invokeExactConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[]) */ public static Object invokeExactConstructor(Class klass, Object arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { Object[] args = { arg }; return invokeExactConstructor(klass, args); }