目录
使用方法
可以使用继承类
ClassA classA =
(ClassA)Class.forName("ClassA").getConstructor(ClassB.class).newInstance(classB)
forName
@CallerSensitive
public static Class<?> forName(String var0) throws ClassNotFoundException {
Class var1 = Reflection.getCallerClass();
return forName0(var0, true, ClassLoader.getClassLoader(var1), var1);
}
getConstructor
@CallerSensitive
public Constructor<T> getConstructor(Class... var1) throws NoSuchMethodException, SecurityException {
this.checkMemberAccess(0, Reflection.getCallerClass(), true);
return this.getConstructor0(var1, 0);
}
newInstance
@CallerSensitive
public T newInstance(Object... var1) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
if (!this.override && !Reflection.quickCheckMemberAccess(this.clazz, this.modifiers)) {
Class var2 = Reflection.getCallerClass();
this.checkAccess(var2, this.clazz, (Object)null, this.modifiers);
}
if ((this.clazz.getModifiers() & 16384) != 0) {
throw new IllegalArgumentException("Cannot reflectively create enum objects");
} else {
ConstructorAccessor var4 = this.constructorAccessor;
if (var4 == null) {
var4 = this.acquireConstructorAccessor();
}
Object var3 = var4.newInstance(var1);
return var3;
}
}