Java Constructor .newInstance (Object . . . initargs)

Syntax

Constructor.newInstance(Object ... initargs) has the following syntax.

public T newInstance(Object ... initargs)  
            throws InstantiationException ,   
                   IllegalAccessException ,   
                   IllegalArgumentException ,   
                   InvocationTargetException

Example

In the following code shows how to use Constructor.newInstance(Object ... initargs) method.


import java.awt.Point;
import java.lang.reflect.Constructor;
/*  ww  w  .j  av  a2 s.  c o  m*/
public class Main {
  public static void main(String[] argv) throws Exception {
    Constructor con = Point.class.getConstructor(new Class[] { 
                               int.class, int.class });
    Point obj = 
        (Point) con.newInstance(new Object[] { 
                            new Integer(1), new Integer(1) });
  }
}




















Home »
  Java Tutorial »
    java.lang.reflect »




Array
Constructor
Field
Method
Modifier
ParameterizedType
TypeVariable