添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
刀枪不入的啄木鸟  ·  string ...·  1 年前    · 
阳刚的伏特加  ·  python opencv ...·  2 年前    · 
玩篮球的菠萝  ·  2023 ...·  3 年前    · 

Java Class getClassLoader() Method

The getClassLoader() method of java Class class returns the class loader for the class which called this method. If this class is loaded by the bootstrap class loader, then it will return null.

Syntax

public ClassLoader getClassLoader()

Parameter

No parameter is passed.

Returns

Return the class loader.

Throws

SecurityException

Example 1

//import statements import java.lang.*; public class ClassgetClassLoaderExample1 { public static void main(String[] args) { try { Class clsobj = Class.forName("Class.ClassgetClassLoaderExample1"); ClassLoader ClsLoader = clsobj.getClassLoader(); if (ClsLoader == null) { System.out.println("System class was used."); } else { // returns the class loader Class loaderCls = ClsLoader.getClass(); System.out.println("Associated with ClassLoader = " +loaderCls.getName()); } catch (ClassNotFoundException e) { System.out.println(e.toString()); //coverting exception object to string and printing it Test it Now

Output:

Associated with ClassLoader = sun.misc.Launcher$AppClassLoader

Example 2

//import statements... public class ClassgetClassLoaderExample2 { public static void main(String[] args) throws Exception { Class clsobj = Class.forName("java.lang.String"); ClassLoader ClassLoader = clsobj.getClassLoader(); if (ClassLoader == null) { System.out.println("System class is used..."); } else { Class loaderClass = ClassLoader.getClass(); System.out.println(loaderClass.getName()); Test it Now

Output:

System class is used...
Next TopicJava Class