[JVM] study notes Class.forName way to learn

Version of the source code for the three parameters

 

 doc document translation

Using the given class loader (i.e., third argument) returns with the given string name (first parameter) Class object class or the associated interface. To a fully qualified name (getName returns the same format) of a given class or interface, this method attempts to find, load and link the class or interface. Specified class loader for loading classes or interfaces. If the load parameter is null, the class is loaded by the boot class loader. Only when the initialize parameter is true before and has not been initialized, it will initialize the class. 
If the name represents a primitive type or void, it will try to name the name of the unnamed package to find user-defined classes. Therefore, this method can not be used to obtain substantially Class object to represent any type or of void. 
If the class represents an array name, type of the loading assembly array class but not initialized. For example, in an instance method, the expression is: 
the Class.forName ( "Foo") 
is equivalent to: 
Class.forName (. "Foo", to true, this.getClass () getClassLoader ()) 
Note that this method will lead to and section 12.2 of the Java language specification, section 12.3 and 12.4 in the specified load, or link initialization related errors. Note that this method does not check whether the class that the caller can access the requested. 
If the loader is null, and there is a security manager and the caller's class loader is not null, this method uses RuntimePermission ( "getClassLoader") permission to call checkPermission method of the security manager to ensure that you can access the bootstrap class loader . 
The Parameters: 
  name - fully qualified name of the desired class initialize - if true, then initialize the class


  . See the Java Language Specification Section 12.4. 
  loader - the class must be loaded class loader 
Returns: 
  represents the class of the desired object class 
Throws By: 
  LinkageError - If the link fails 
  ExceptionInInitializerError - If this method triggered initialization fails  
  ClassNotFoundException - if the specified class loader can not find the class 
Since: 
  1.2 
See Also: 
  forName (String), ClassLoader 
external annotation: 
  @ org.jetbrains.annotations.NonNls

 

Guess you like

Origin www.cnblogs.com/heben/p/11455600.html