Constructor: newInstance(Object... initargs) : Constructor « java.lang.reflect « Java by API






Constructor: newInstance(Object... initargs)

  


import java.lang.reflect.Constructor;

public class Main {
  public static void main(final String[] args) throws Exception {
    final Class[] ARG_TYPES = new Class[] { String.class };

    Constructor cst = Integer.class.getConstructor(ARG_TYPES);

    System.out.println(cst.newInstance(new Object[] { "45" }));
  }
}

   
    
  








Related examples in the same category

1.Constructor: getExceptionTypes()
2.Constructor: getParameterTypes()
3.Constructor: getModifiers()
4.Constructor: getName()
5.Constructor: setAccessible(boolean flag)
6.Constructor: toGenericString()