ClassLoader's accumulation

xiaoxiao2021-04-03  245

Class.Forname (String ClassName); Today, when using this method Loader Class, ADDCOMMAND CLASS NOT FOUND has appeared, and I just thought it was ClasName to write wrong. After careful examination, I didn't have this problem. Open the JDK document, see the classname - the full qualified name of the desired class. And the class t = Class.Forname ("java.lang.thread") is suddenly realized, we should be complete Name (including Package path).

There are so many words on jdk: Invoking this method is equivalent to:. Class.forName (className, true, currentLoader), where currentLoader denotes the defining class loader of the current class that is the last call of the former or the latter, but is Automatic two parameters are set to default value. CurrentLoader can be obtained by this.getClass (). GetClassLoader (). But this method is likely to return null, why? This involves the problem of class loading system. If this class is booted by bootstrap loader, it is null. Is that it got NULL, then call down, turn out an exception? Referring JDK documentation, the above described as follows: If the loader is null, and a security manager is present, and the caller's class loader is not null, this method calls the security manager's checkPermission method with a RuntimePermission ( "getClassLoader") permission to ensure it's Ok to access the bootstrap class loading.

转载请注明原文地址:https://www.9cbs.com/read-131611.html

New Post(0)