Java类类getClassLoader()方法及示例

类的类getClassLoader()方法 (Class class getClassLoader() method)

  • getClassLoader() method is available in java.lang package.

    getClassLoader()方法在java.lang包中可用。

  • getClassLoader() method is used to return the ClassLoader that loads the class or interface.

    getClassLoader()方法用于返回加载类或接口的ClassLoader。

  • getClassLoader() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    getClassLoader()方法是一个非静态方法,只能通过类对象进行访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • getClassLoader() method may throw SecurityException at the time of loading class or interface.

    在加载类或接口时, getClassLoader()方法可能会引发SecurityException

    SecurityException: In this exception, its checkPermission() method does not allow access classloader for the class when the security manager exists.

    SecurityException :在此异常中,当安全管理器存在时,其checkPermission()方法不允许访问该类的类加载器。

Syntax:

句法:

    public ClassLoader getClassLoader();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of this method is ClassLoader, it returns the following values based on the given cases,

此方法的返回类型为ClassLoader ,它根据给定的情况返回以下值:

  • It returns class loader that loads the class denoted by this object.

    它返回类加载器,该加载器加载此对象表示的类。

  • It returns null in case of bootstrap class loader because we don't need to implement bootstrap class loader.

    如果使用自举类加载器,则返回null ,因为我们无需实现自举类加载器。

Example:

例:

// Java program to demonstrate the example 
// of ClassLoader getClassLoader() method of Class 
public class GetClassLoaderOfClass {
public static void main(String[] args) throws Exception {
// It returns the Class object attached with the given 
//classname
Class cl = Class.forName("GetClassLoaderOfClass");
// By using getClassLoader() is to load the class
ClassLoader class_load = cl.getClassLoader();
// If any ClassLoader associate with the Class
if (class_load != null) {
Class load_class = class_load.getClass();
System.out.print("Associated Loader Class: ");
System.out.print(load_class.getName());
}
// No Loader associated with the class
else
System.out.println("No system loader associated with the class");
}
}

Output

输出量

Associated Loader Class: jdk.internal.loader.ClassLoaders$AppClassLoader

翻译自: https://www.includehelp.com/java/class-class-getclassloader-method-with-example.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/545287.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

小白学算法:买卖股票的最佳时机!

作者 | 王磊来源 | Java中文社群(ID:javacn666)转载请联系授权(微信ID:GG_Stone)本文已收录至 Github《小白学算法》系列:https://github.com/vipstone/algorith今天蚂蚁集团(支付宝…

第十一章并发控制

第十一章并发控制11.1_并发控制概述11.2_封锁11.1_并发控制概述 事务是并发控制的基本单位 并发操作带来的数据不一致性包括丢失修改、不可重复读、读“赃”数据 11.2_封锁 两种封锁协议:排他锁(写锁)和共享锁(读锁&#xff09…

《APUE》第6章笔记

这一章主要介绍了口令文件和组文件的结构和一些围绕这些结构的函数。 口令文件即passwd就是在/etc/passwd中可以查阅。其结构是: 上图四个平台能支持的就用黑点表示。 因为加密口令这一项放在passwd这个人人可读的文件中,可能会有安全问题。所以现在的Li…

Oracle笔记:备份还原

--------------备份还原-------------------- --物理备份 --逻辑备份 1)传统工具: exp导出、imp导入 实质:调用sql指令,导入\导出数据,速度较慢 可以运行在客户端,也可以运行在服务器端, 在cmd窗…

Java DataOutputStream writeByte()方法与示例

DataOutputStream类writeByte()方法 (DataOutputStream Class writeByte() method) writeByte() method is available in java.io package. writeByte()方法在java.io包中可用。 writeByte() method is used to write the given value as one-byte value to the basic stream a…

聊聊近期的感受和10月文章精选!

先来看本月的原创文章汇总,其中算法部分也有少量 9 月份的文章,这样汇总起来大家看起来更方便,目录如下。算法系列小白学算法第1篇:一文详解「栈」和手撸栈的两种方法!小白学算法第2篇:JDK 竟然是这样实现栈…

第六章关系数据理论

第六章关系数据理论6.1_问题的提出(略)6.2_规范化6.2.1_函数依赖6.2.2_码6.2.3_范式6.2.4_2NF6.2.5_3NF6.2.6_BCNF6.2.7_多值依赖6.2.8_4NF6.2.9_规范化小结6.3_Armstrong公理系统6.3.1_函数依赖闭包6.3.2_最小依赖集6.3.3_转换为3NF的保持函数依赖的分解…

Oracle数据字典

--用户信息 select * from dba_users; --角色信息 select * from dba_roles; --权限信息 select * from dba_role_privs;--方案(Schema)是数据库对象的集合,每个用户都对应一个方案。用户是各种对象的所有者, --方案是对象的组织形式。 --用户与方案是一…

Github上的热门iOS开源项目:AFNetworking、MagicalRecord、BlocksKit以及XVim

1. AFNetworking AFNetworking是一个非常受欢迎的轻量级的iOS、Mac OS X网络通信类库。它建立在NSURLConnection、NSOperation以及其技术的基础上,有着精心设计的模块结构和功能丰富的API,让很多网络通信功能的实现变得十分简单。 附件:/c…

队列实现栈的3种方法,全都击败了100%的用户!

作者 | 王磊来源 | Java中文社群(ID:javacn666)转载请联系授权(微信ID:GG_Stone)本文已收录至 Github《小白学算法》系列:https://github.com/vipstone/algorith之前我们讲过《用两个栈实现一个…

Java类类getConstructor()方法及示例

类的类getConstructor()方法 (Class class getConstructor() method) getConstructor() method is available in java.lang package. getConstructor()方法在java.lang包中可用。 getConstructor() method is used to return a Constructor object that reflects the given pub…

where、having、group by、order by、count的使用注意

where、having、group by、order by、count的使用注意1_where、having、group by、order by的顺序2_group by的作用3_where和group by的组合4_group by和having的组合5_where、having、group by的组合使用6_count与group by的组合使用1_where、having、group by、order by的顺序…

Oracle备份还原

Oracle有两类备份方式: (1)物理备份:是将实际组成数据库的操作系统文件从一处拷贝到另一处的备份过程,通常是从磁盘到磁带。物理备份又分为冷备份、热备份; (2)逻辑备份&#xff1…

Eclipse快捷键-方便查找

【Ct rlT】 搜索当前接口的实现类 1. 【ALT /】 此快捷键为用户编辑的好帮手,能为用户提供内容的辅助,不要为记不全方法和属性名称犯愁,当记不全类、方法和属性的名字时,多体验一下【ALT /】快捷键带来的好处吧。 2. 【Ct rlO】…

很实用的21个SQL小技巧!

前言每一个好习惯都是一笔财富,本文基于MySQL,分SQL后悔药, SQL性能优化,SQL规范优雅三个方向,分享写SQL的21个好习惯,谢谢阅读,加油哈~1. 写完SQL先explain查看执行计划(SQL性能优化…

Java ByteArrayOutputStream size()方法与示例

ByteArrayOutputStream类size()方法 (ByteArrayOutputStream Class size() method) size() method is available in java.io package. size()方法在java.io包中可用。 size() method is used to return the current size of the buffer exists. size()方法用于返回缓冲区当前存…

Oracle备份文件名获取系统时间的做法(windows)

在对数据库进行备份时,用数据泵的方法,需要执行一段代码: --建目录 create directory dir as d:\bak;--给用户授权使用目录 grant read,write on directory dir to scott;--在cmd中输入以下代码 expdp scott/tigerXE directorydir dumpfileab…

java getmonth_Java LocalDateTime类| 带示例的getMonth()方法

java getmonthLocalDateTime类getMonth()方法 (LocalDateTime Class getMonth() method) getMonth() method is available in java.time package. getMonth()方法在java.time包中可用。 getMonth() method is used to get the field value month-of-year based on the enum Mon…

阿里最喜欢问的多线程顺序打印的5种解法!

Keeper导读大家在换工作面试中,除了一些常规算法题,还会遇到各种需要手写的题目,所以打算总结出来,给大家个参考。全文 2929 字,剩下的是代码,P6 及以下阅读只需要 8 分钟,高 P 请直接关闭第一篇…

CSS入门

CSS入门1_CSS概要1.1_CSS引入方式2_CSS选择器3_字体样式3.1_字体属性3.2_字体类型:font-family3.3_字体大小:font-size3.4_字体粗细:font-weight3.5_字体颜色:color3.6_总结4_文本样式4.1_文本样式属性4.2_首行缩进:te…