JDK-4993813 : (reflect) Need a way to force a class to be initialized.
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_8,windows_xp
  • CPU: generic,x86
  • Submitted: 2004-02-12
  • Updated: 2020-06-11
  • Resolved: 2020-06-11
Related Reports
Duplicate :  
Relates :  
Relates :  
There is no direct way to force a class to be initialized.  Now that class
literals do not do that, it would be extremely helpful for there to be a
direct way to force the initialization.  Please add a method

	public Class<T> Class.initialize();

to force the class to be initialized.  That would allow the idiom


to be used as a class literal for an initialized class.

Closing as duplicate of JDK-8245871.

SUGGESTED FIX public class Class { ... /** Forces the class to be initialized. */ public Class<T> initialize() { forName(getName(), true, getClassLoader()); return this; } }