-
Enhancement
-
Resolution: Unresolved
-
P4
-
8
-
None
-
generic
-
generic
Class.forName(String cn) is a convenient method equivalent to:
Class.forName(cn, true, currentLoader);
Class.forName(String) method will load a class and its <clinit> will
be invoked.
To load a class but to skip class initialization using the defining loader
of the caller's class, it will have to call, e.g. if call from an instance method:
Class.forName(cn, false, this.getClass().getClassLoader());
Additional comment from Remi Forax [1]:
> In fact, this method is really useful, most of the tools that does
> bytecode transformation at runtime (most O/R mappers,
> dynamic language runtimes, profilers, code coverage tools, etc)
> are now required to compute the stack frame attribute which requires to
> compute the lower upper bound of a set of types. For that, being able
> to crawle the type hierachy without loading the static initializer
> is a must have.
[1] http://mail.openjdk.java.net/pipermail/jigsaw-dev/2012-May/002529.html
Class.forName(cn, true, currentLoader);
Class.forName(String) method will load a class and its <clinit> will
be invoked.
To load a class but to skip class initialization using the defining loader
of the caller's class, it will have to call, e.g. if call from an instance method:
Class.forName(cn, false, this.getClass().getClassLoader());
Additional comment from Remi Forax [1]:
> In fact, this method is really useful, most of the tools that does
> bytecode transformation at runtime (most O/R mappers,
> dynamic language runtimes, profilers, code coverage tools, etc)
> are now required to compute the stack frame attribute which requires to
> compute the lower upper bound of a set of types. For that, being able
> to crawle the type hierachy without loading the static initializer
> is a must have.
[1] http://mail.openjdk.java.net/pipermail/jigsaw-dev/2012-May/002529.html
- relates to
-
JDK-4993813 (reflect) Need a way to force a class to be initialized.
- Closed
-
JDK-7193339 Prepare system classes be defined by a non-null module loader
- Closed
-
JDK-8148403 Preverifier needs API similar to Class.forName() that loads and links a class
- Closed