United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4993813 : (reflect) Need a way to force a class to be initialized.

Details
Type:
Enhancement
Submit Date:
2004-02-12
Status:
Open
Updated Date:
2013-04-11
Project Name:
JDK
Resolved Date:
Component:
core-libs
OS:
solaris_8,windows_xp
Sub-Component:
java.lang:reflect
CPU:
x86,generic
Priority:
P3
Resolution:
Unresolved
Affected Versions:
5.0
Targeted Versions:

Related Reports
Duplicate:
Relates:

Sub Tasks

Description
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

	X.class.initialize()

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

                                    

Comments
SUGGESTED FIX

public class Class { ...

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

}
                                     
2004-06-11



Hardware and Software, Engineered to Work Together