Java Reflection Constructor Invoke invokeConstructor(Class type, Object value)

Here you can find the source of invokeConstructor(Class type, Object value)

Description

invoke Constructor

License

Open Source License

Declaration

public static <T> T invokeConstructor(Class<T> type, Object value)
            throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException,
            IllegalAccessException, InvocationTargetException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.*;

public class Main {
    public static <T> T invokeConstructor(Class<T> type, Object value)
            throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException,
            IllegalAccessException, InvocationTargetException {
        return invokeConstructor(type, value, value.getClass());
    }// ww w . j a  v  a  2s  .  c  o  m

    public static <T> T invokeConstructor(Class<T> type, Object value, Class<?> objectType)
            throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException,
            IllegalAccessException, InvocationTargetException {
        Constructor<T> constructor = type.getConstructor(objectType);
        return constructor.newInstance(value);
    }
}

Related

  1. invokeConstructor(Class clazz, Class[] paramTypes, Object[] params)
  2. invokeConstructor(Class clazz, Object... parameters)
  3. invokeConstructor(Class objectClass, Class[] classes, Object... params)
  4. invokeConstructor(Class clazz, Class[] argTypes, Object[] args)
  5. invokeConstructor(Class cls)
  6. invokeConstructor(Constructor constructor, Object... arguments)
  7. invokeConstructor(Constructor constructor, Object... parameters)
  8. invokeConstructor(final Class clazz, final Class[] paramTypes, final Object... args)
  9. invokeConstructor(final Constructor constructor, final Object... args)