public final class Class<T>extends Objectimplements Serializable, GenericDeclaration, Type, AnnotatedElement
Class類的對象.newInstance();
public T newInstance()throws InstantiationException, IllegalAccessException
class Phone {
public Phone() {
System.out.println("Phone類的構造方法");
}
public String toString() {
return "是一部手機";
}
}
public class Test {
public static void main(String[] args) throws Exception {
Class<Phone> cls = Phone.class;
Phone p2 = cls.newInstance();
System.out.println("p2: " + p2);
}
}