これは、呼び出し側クラスローダーを使用します。forName()のソースコード:
public static Class<?> forName(String className)
throws ClassNotFoundException {
return forName0(className, true, ClassLoader.getCallerClassLoader());
}
そして、getCallerClassLoader()は次のとおりです。
static ClassLoader getCallerClassLoader() {
// NOTE use of more generic Reflection.getCallerClass()
Class caller = Reflection.getCallerClass(3);
// This can be null if the VM is requesting it
if (caller == null) {
return null;
}
// Circumvent security check since this is package-private
return caller.getClassLoader0();
}
そして、このメソッドの説明は次のとおりです。
// Returns the invoker's class loader, or null if none.