文章来源:嗨学网 敏而好学论坛www.piaodoo.com 欢迎大家相互学习

在一次源码查看ThreadGroup的时候,看到一段代码,为以下:

/*
   * @throws NullPointerException if the parent argument is {@code null}
   * @throws SecurityException   if the current thread cannot create a
   *                thread in the specified thread group.
   */
  private static Void checkParentAccess(ThreadGroup parent) {
    parent.checkAccess();
    return null;
  }

这个方法用于检查parent访问权限,然后直接返回null,方法的返回类型为Void原以为Void类为void类的包装类,但是查看Void类的

源码后发现并不是如此,Void类的源码如下:

/**
 * The {@code Void} class is an uninstantiable placeholder class to hold a
 * reference to the {@code Class} object representing the Java keyword
 * void.
 *
 * @author unascribed
 * @since  JDK1.1
 */
public final
class Void {
  /**
   * The {@code Class} object representing the pseudo-type corresponding to
   * the keyword {@code void}.
   */
  @SuppressWarnings("unchecked")
  public static final Class<Void> TYPE = (Class<Void>) Class.getPrimitiveClass("void");
  /*
   * The Void class cannot be instantiated.
   */
  private Void() {}
}

在最上面的注释中,描述的是

The {@code Void} class is an uninstantiable placeholder class to hold a
* reference to the {@code Class} object representing the Java keyword

这段话的意思就是Void类是一个不可实例化的占位符类,它持有对标识Java关键字void的Class对象的引用。

并且本身的构造函数为private,并且注明:

public final class Void {}

final表明这个类是不允许被其他类继承的。

/*
 * The Void class cannot be instantiated.
 */

即该类是不可以实例化的。

Void类可能本身作用就只是不起任何作用,但是本身只是一个占位符类。即Void类本身只是一个占位符类,不能被实例化,多用于泛型中作占位符使用。

总结

以上就是本文关于java.lang.Void类源码解析的全部内容,希望对大家有所帮助。感兴趣的朋友可以参阅:RateLimiter 源码分析、基于ZooKeeper实现队列源码、Spring SpringMVC在启动完成后执行方法源码解析等,有什么问题可以随时留言,小编会及时回复大家的。

原文地址是:http://www.piaodoo.com/thread-13240-1-2.html 丝袜控www.txdah.com 131www.buzc.org学习之外可赏心悦目有助更好地学习!

java.lang.Void类源码解析_java - JAVA的更多相关文章

  1. java.lang.Boolean 类源码解析

    Boolean源码比较简单. public final class Boolean implements java.io.Serializable, Comparable<Boolean> ...

  2. Java集合---Array类源码解析

    Java集合---Array类源码解析              ---转自:牛奶.不加糖 一.Arrays.sort()数组排序 Java Arrays中提供了对所有类型的排序.其中主要分为Prim ...

  3. java.lang.String 类源码解读

    String类定义实现了java.io.Serializable, Comparable<String>, CharSequence 三个接口:并且为final修饰. public fin ...

  4. java.lang.Long 类源码解读

    总体阅读了Long的源码,基本跟Integer类类似,所以特别全部贴出源码,直接注释进行理解. // final修饰符 public final class Long extends Number i ...

  5. java.lang.Byte 类源码浅析

    Byte 类字节,属于Number. public final class Byte extends Number implements Comparable<Byte> { /** * ...

  6. Java集合---Arrays类源码解析

    一.Arrays.sort()数组排序 Java Arrays中提供了对所有类型的排序.其中主要分为Primitive(8种基本类型)和Object两大类. 基本类型:采用调优的快速排序: 对象类型: ...

  7. java.lang.system 类源码解读

    通过每块代码进行源码解读,并发现源码使用的技术栈,扩展视野. registerNatives 方法解读 /* register the natives via the static initializ ...

  8. [源码解析] 当 Java Stream 遇见 Flink

    [源码解析] 当 Java Stream 遇见 Flink 目录 [源码解析] 当 Java Stream 遇见 Flink 0x00 摘要 0x01 领域 1.1 Flink 1.2 Java St ...

  9. Java集合类:AbstractCollection源码解析

    一.Collection接口 从<Java集合:整体结构>一文中我们知道所有的List和Set都继承自Collection接口,该接口类提供了集合最基本的方法,虽然List接口和Set等都 ...

随机推荐

  1. 求旋转数组的最小数字(剑指offer)

    把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数 ...

  2. PushConsumer 消费消息

    CLUSTERING 模式下,消费者会订阅 retry topic // DefaultMQPushConsumerImpl#copySubscription private void copySub ...

  3. Octavia health-manager 与 amphora 故障修复的实现与分析

    目录 文章目录 目录 Health Manager 监控 amphora 健康状态 故障转移 故障迁移测试 Health Manager Health Manager - This subcompon ...

  4. frewalld假端口

    之前服务器没有开启firewalld,上面有lnmp.zabbix服务,后来开启了防火墙,发现端口都在,但是不能访问zabbix,后来用firewalld把端口重新开启.重新加载后才可以访问,这就是f ...

  5. .net 部署到服务端IIS,Process调用exe程序无法运行问题解决

    场景: 开发某一功能将html内容转换为pdf,采用第三方插件wkhtmltopdf.exe进行转换.在本地调试正常运行,部署到服务端后文件没有正常生成. IIS中,Process打不开cmd程序,程 ...

  6. 20191127 Spring Boot官方文档学习(4.13)

    4.13.Messaging Spring框架为与消息传递系统集成提供了广泛的支持,从使用JmsTemplate简化JMS API到完整的异步接收消息的基础结构.Spring AMQP为高级消息队列协 ...

  7. ConfigurationManager.ConnectionStrings 属性

    public static ConnectionStringSettingsCollection ConnectionStrings { get; } App.config <?xml vers ...

  8. 三、Zabbix-zabbix server部署-zabbix server

    LNMP基础环境准备完成,进行zabbix server部署参考官方文档: [https://www.zabbix.com/documentation/3.4/zh/manual/installati ...

  9. 使用certbot 为nginx或openresty启用https

    certbot 使用letsencrypt 生成免费https证书 以下内容网上整理,原文地址 https://segmentfault.com/a/1190000005797776 -------- ...

  10. 【转】centos7安装

    转自:https://blog.csdn.net/qq_42570879/article/details/82853708 1.CentOS下载CentOS是免费版,推荐在官网上直接下载,网址:htt ...