日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java.lang 源码剖析_java.lang.Void类源码解析

發布時間:2023/12/2 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java.lang 源码剖析_java.lang.Void类源码解析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在一次源碼查看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 TYPE = (Class) 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在啟動完成后執行方法源碼解析等,有什么問題可以隨時留言,小編會及時回復大家的。

總結

以上是生活随笔為你收集整理的java.lang 源码剖析_java.lang.Void类源码解析的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。