import java.lang.reflect.Constructor;
public class Main {
public static void main(String[] args) throws Exception {
Class clazz = String.class;
Constructor constructor = clazz.getConstructor(new Class[] { String.class });
String object = (String) constructor.newInstance(new Object[] { "Hello World!" });
System.out.println("String = " + object);
constructor = clazz.getConstructor(new Class[] { StringBuilder.class });
object = (String) constructor
.newInstance(new Object[] { new StringBuilder("Hello Universe!") });
System.out.println("String = " + object);
}
}
|