Java ClassLoader getSystemClassLoader()方法与示例
ClassLoader類getSystemClassLoader()方法 (ClassLoader Class getSystemClassLoader() method)
getSystemClassLoader() method is available in java.lang package.
getSystemClassLoader()方法在java.lang包中可用。
getSystemClassLoader() method is used to find the System class loader for delegation and this will be the default delegation parent for the new instance of the ClassLoader.
getSystemClassLoader()方法用于查找要委派的系統類加載器,這將是ClassLoader新實例的默認委派父級。
getSystemClassLoader() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get any error.
getSystemClassLoader()方法是一個靜態方法,可以使用類名進行訪問,如果嘗試使用類對象訪問該方法,則不會出現任何錯誤。
getSystemClassLoader() method may throw an exception at the time of checking security constraints.
在檢查安全性約束時, getSystemClassLoader()方法可能會引發異常。
- SecurityException: In this exception, its SecurityException :在此異常中,當安全管理器存在時,其checkPermission() method does not allow access to the system classloader when the security manager exists.checkPermission()方法不允許訪問系統類加載器。
- IllegalStateException: In this exception when called recursively during the construction of the class loader given by the property IllegalStateException :在此異常中,當在構造由屬性"java.system.class.loader".“ java.system.class.loader”給出的類加載器期間遞歸調用時。
Syntax:
句法:
static ClassLoader getSystemClassLoader();Parameter(s):
參數:
It does not accept any parameter.
它不接受任何參數。
Return value:
返回值:
The return type of this method is ClassLoader, it returns the system class loader of ClassLoader type.
該方法的返回類型為ClassLoader ,它返回ClassLoader類型的系統類加載器 。
Example:
例:
// Java program to demonstrate the example // of ClassLoader getSystemClassLoader() method of ClassLoader public class GetSystemClassLoader {public static void main(String[] args) throws Exception {// It returns the Class object attached with the given // classnameClass cl = Class.forName("GetSystemClassLoader");// It returns the ClassLoader object attached with the given // classnameClassLoader loader = cl.getClassLoader();// Display Loader ClassSystem.out.println(loader.getClass());// It returns the SystemClassLoader object attached with the // given classnameloader = loader.getSystemClassLoader();// Display SystemClassLoader ClassSystem.out.println(loader.getClass());} }Output
輸出量
class jdk.internal.loader.ClassLoaders$AppClassLoader class jdk.internal.loader.ClassLoaders$AppClassLoader翻譯自: https://www.includehelp.com/java/classloader-getsystemclassloader-method-with-example.aspx
總結
以上是生活随笔為你收集整理的Java ClassLoader getSystemClassLoader()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: frexp 中文_带有Python示例的
- 下一篇: Java类类getResourceAsS