Create an Object Using a Constructor Object in Java
Description
The following code shows how to create an Object Using a Constructor Object.
Example
//w ww . java 2 s . co m
import java.lang.reflect.Constructor;
public class Main {
public static void main(String[] argv) throws Exception {
Constructor con = java.awt.Point.class.getConstructor(new Class[] { int.class, int.class });
java.awt.Point obj = (java.awt.Point) con.newInstance(new Object[] { new Integer(123),
new Integer(123) });
System.out.println(con);
System.out.println(obj);
}
}
The code above generates the following result.