# HG changeset patch # User Jaroslav Tulach # Date 1358979423 -3600 # Node ID ded0000c296299efe7d9774e60b7f1fbf90a57f8 # Parent f06b2d18eb52d2506da34388a86fd4dd18ae456f Class.forName with parameters diff -r f06b2d18eb52 -r ded0000c2962 emul/mini/src/main/java/java/lang/Class.java --- a/emul/mini/src/main/java/java/lang/Class.java Wed Jan 23 23:16:47 2013 +0100 +++ b/emul/mini/src/main/java/java/lang/Class.java Wed Jan 23 23:17:03 2013 +0100 @@ -160,6 +160,74 @@ } return c; } + + + /** + * Returns the {@code Class} object associated with the class or + * interface with the given string name, using the given class loader. + * Given the fully qualified name for a class or interface (in the same + * format returned by {@code getName}) this method attempts to + * locate, load, and link the class or interface. The specified class + * loader is used to load the class or interface. If the parameter + * {@code loader} is null, the class is loaded through the bootstrap + * class loader. The class is initialized only if the + * {@code initialize} parameter is {@code true} and if it has + * not been initialized earlier. + * + *

If {@code name} denotes a primitive type or void, an attempt + * will be made to locate a user-defined class in the unnamed package whose + * name is {@code name}. Therefore, this method cannot be used to + * obtain any of the {@code Class} objects representing primitive + * types or void. + * + *

If {@code name} denotes an array class, the component type of + * the array class is loaded but not initialized. + * + *

For example, in an instance method the expression: + * + *

+ * {@code Class.forName("Foo")} + *
+ * + * is equivalent to: + * + *
+ * {@code Class.forName("Foo", true, this.getClass().getClassLoader())} + *
+ * + * Note that this method throws errors related to loading, linking or + * initializing as specified in Sections 12.2, 12.3 and 12.4 of The + * Java Language Specification. + * Note that this method does not check whether the requested class + * is accessible to its caller. + * + *

If the {@code loader} is {@code null}, and a security + * manager is present, and the caller's class loader is not null, then this + * method calls the security manager's {@code checkPermission} method + * with a {@code RuntimePermission("getClassLoader")} permission to + * ensure it's ok to access the bootstrap class loader. + * + * @param name fully qualified name of the desired class + * @param initialize whether the class must be initialized + * @param loader class loader from which the class must be loaded + * @return class object representing the desired class + * + * @exception LinkageError if the linkage fails + * @exception ExceptionInInitializerError if the initialization provoked + * by this method fails + * @exception ClassNotFoundException if the class cannot be located by + * the specified class loader + * + * @see java.lang.Class#forName(String) + * @see java.lang.ClassLoader + * @since 1.2 + */ + public static Class forName(String name, boolean initialize, + ClassLoader loader) + throws ClassNotFoundException + { + return forName(name); + } @JavaScriptBody(args = {"n", "c" }, body = "if (vm[c]) return vm[c].$class;\n"