-
Enhancement
-
Resolution: Incomplete
-
P4
-
None
-
9
-
generic
-
generic
A DESCRIPTION OF THE REQUEST :
Prior to JDK 9, one could use reflection to bypass accessing checking and invoke the protected ClassLoader.findLoadedClass method to determine if a class with a given name had been loaded. Unlike Class.forName, the findLoadedClass method does not try to load the class. A public API is needed to make this functionality available in JDK 9 and later.
JUSTIFICATION :
To support loose coupling, it is useful to be able to test that a class has been loaded before trying to use it. A clear example is calling a method to release resources. If the class has not been loaded, it has no resources, so there is no point in loading the class to ask it to release resources.
CUSTOMER SUBMITTED WORKAROUND :
An alternative is to check for the package of the class being defined. This may or may not be equivalent to checking for the class being loaded.
Prior to JDK 9, one could use reflection to bypass accessing checking and invoke the protected ClassLoader.findLoadedClass method to determine if a class with a given name had been loaded. Unlike Class.forName, the findLoadedClass method does not try to load the class. A public API is needed to make this functionality available in JDK 9 and later.
JUSTIFICATION :
To support loose coupling, it is useful to be able to test that a class has been loaded before trying to use it. A clear example is calling a method to release resources. If the class has not been loaded, it has no resources, so there is no point in loading the class to ask it to release resources.
CUSTOMER SUBMITTED WORKAROUND :
An alternative is to check for the package of the class being defined. This may or may not be equivalent to checking for the class being loaded.