src/java.base/share/classes/java/lang/Class.java
changeset 59137 faac483dfb30
parent 58920 d67ebc838ab8
child 59297 498ce2452972
equal deleted inserted replaced
59136:fc998c509521 59137:faac483dfb30
   323      *             specified name.
   323      *             specified name.
   324      * @throws    LinkageError if the linkage fails
   324      * @throws    LinkageError if the linkage fails
   325      * @throws    ExceptionInInitializerError if the initialization provoked
   325      * @throws    ExceptionInInitializerError if the initialization provoked
   326      *            by this method fails
   326      *            by this method fails
   327      * @throws    ClassNotFoundException if the class cannot be located
   327      * @throws    ClassNotFoundException if the class cannot be located
       
   328      *
       
   329      * @jls 12.2 Loading of Classes and Interfaces
       
   330      * @jls 12.3 Linking of Classes and Interfaces
       
   331      * @jls 12.4 Initialization of Classes and Interfaces
   328      */
   332      */
   329     @CallerSensitive
   333     @CallerSensitive
   330     public static Class<?> forName(String className)
   334     public static Class<?> forName(String className)
   331                 throws ClassNotFoundException {
   335                 throws ClassNotFoundException {
   332         Class<?> caller = Reflection.getCallerClass();
   336         Class<?> caller = Reflection.getCallerClass();
   337     /**
   341     /**
   338      * Returns the {@code Class} object associated with the class or
   342      * Returns the {@code Class} object associated with the class or
   339      * interface with the given string name, using the given class loader.
   343      * interface with the given string name, using the given class loader.
   340      * Given the fully qualified name for a class or interface (in the same
   344      * Given the fully qualified name for a class or interface (in the same
   341      * format returned by {@code getName}) this method attempts to
   345      * format returned by {@code getName}) this method attempts to
   342      * locate, load, and link the class or interface.  The specified class
   346      * locate and load the class or interface.  The specified class
   343      * loader is used to load the class or interface.  If the parameter
   347      * loader is used to load the class or interface.  If the parameter
   344      * {@code loader} is null, the class is loaded through the bootstrap
   348      * {@code loader} is null, the class is loaded through the bootstrap
   345      * class loader.  The class is initialized only if the
   349      * class loader.  The class is initialized only if the
   346      * {@code initialize} parameter is {@code true} and if it has
   350      * {@code initialize} parameter is {@code true} and if it has
   347      * not been initialized earlier.
   351      * not been initialized earlier.
   372      * Java Language Specification</em>.
   376      * Java Language Specification</em>.
   373      * Note that this method does not check whether the requested class
   377      * Note that this method does not check whether the requested class
   374      * is accessible to its caller.
   378      * is accessible to its caller.
   375      *
   379      *
   376      * @param name       fully qualified name of the desired class
   380      * @param name       fully qualified name of the desired class
   377      * @param initialize if {@code true} the class will be initialized.
   381      * @param initialize if {@code true} the class will be initialized (which implies linking).
   378      *                   See Section 12.4 of <em>The Java Language Specification</em>.
   382      *                   See Section 12.4 of <em>The Java Language Specification</em>.
   379      * @param loader     class loader from which the class must be loaded
   383      * @param loader     class loader from which the class must be loaded
   380      * @return           class object representing the desired class
   384      * @return           class object representing the desired class
   381      *
   385      *
   382      * @throws    LinkageError if the linkage fails
   386      * @throws    LinkageError if the linkage fails
   390      *            {@code null}, and the caller does not have the
   394      *            {@code null}, and the caller does not have the
   391      *            {@link RuntimePermission}{@code ("getClassLoader")}
   395      *            {@link RuntimePermission}{@code ("getClassLoader")}
   392      *
   396      *
   393      * @see       java.lang.Class#forName(String)
   397      * @see       java.lang.Class#forName(String)
   394      * @see       java.lang.ClassLoader
   398      * @see       java.lang.ClassLoader
       
   399      *
       
   400      * @jls 12.2 Loading of Classes and Interfaces
       
   401      * @jls 12.3 Linking of Classes and Interfaces
       
   402      * @jls 12.4 Initialization of Classes and Interfaces
   395      * @since     1.2
   403      * @since     1.2
   396      */
   404      */
   397     @CallerSensitive
   405     @CallerSensitive
   398     public static Class<?> forName(String name, boolean initialize,
   406     public static Class<?> forName(String name, boolean initialize,
   399                                    ClassLoader loader)
   407                                    ClassLoader loader)
   425 
   433 
   426     /**
   434     /**
   427      * Returns the {@code Class} with the given <a href="ClassLoader.html#binary-name">
   435      * Returns the {@code Class} with the given <a href="ClassLoader.html#binary-name">
   428      * binary name</a> in the given module.
   436      * binary name</a> in the given module.
   429      *
   437      *
   430      * <p> This method attempts to locate, load, and link the class or interface.
   438      * <p> This method attempts to locate and load the class or interface.
   431      * It does not run the class initializer.  If the class is not found, this
   439      * It does not link the class, and does not run the class initializer.
   432      * method returns {@code null}. </p>
   440      * If the class is not found, this method returns {@code null}. </p>
   433      *
   441      *
   434      * <p> If the class loader of the given module defines other modules and
   442      * <p> If the class loader of the given module defines other modules and
   435      * the given name is a class defined in a different module, this method
   443      * the given name is a class defined in a different module, this method
   436      * returns {@code null} after the class is loaded. </p>
   444      * returns {@code null} after the class is loaded. </p>
   437      *
   445      *
   463      *         permission check will be performed when a class loader calls
   471      *         permission check will be performed when a class loader calls
   464      *         {@link ModuleReader#open(String)} to read the bytes of a class file
   472      *         {@link ModuleReader#open(String)} to read the bytes of a class file
   465      *         in a module.</li>
   473      *         in a module.</li>
   466      *         </ul>
   474      *         </ul>
   467      *
   475      *
       
   476      * @jls 12.2 Loading of Classes and Interfaces
       
   477      * @jls 12.3 Linking of Classes and Interfaces
   468      * @since 9
   478      * @since 9
   469      * @spec JPMS
   479      * @spec JPMS
   470      */
   480      */
   471     @CallerSensitive
   481     @CallerSensitive
   472     public static Class<?> forName(Module module, String name) {
   482     public static Class<?> forName(Module module, String name) {