利用反射可以动态的创建对象
package Reflect;
import java.lang.reflect.InvocationTargetException;
public class ReflectTest {
public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
Class cl=new Iphone().getClass();
cl=Iphone.class;
try {
cl=Class.forName("Reflect.Iphone");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Iphone iphone=(Iphone) cl.getConstructor().newInstance();
System.out.println(iphone);
}
}
class Iphone{
public Iphone(){
}
}