Java 源码赏析 - java.lang - Void

被人鄙视了,于是也来读读源码。。。

 

package java.lang;

/**
 * The Void class is an uninstantiable placeholder class to hold a
 * reference to the Class object representing the Java keyword
 * void.
 *
 * @author  unascribed
 * @version %I%, %G%
 * @since   JDK1.1
 */
public final
class Void {

    /**
     * The Class object representing the pseudo-type corresponding to
     * the keyword void.
     */
    public static final Class<Void> TYPE = Class.getPrimitiveClass("void");

    /*
     * The Void class cannot be instantiated.
     */
    private Void() {}
}

原来Java里面有个Void类,是一个不可实例化的占位(placeholder)类,它持有一个Void类型的类变量来表示Java里面的关键字void。

Class.getPrimitiveClass() 原来还有这个方法,在什么场景下使用?

是不是所有的关键字都有对应的一个类呢?

这些关键字在编译好的文件中是怎样表示的?

Java解释器又是怎样工作的?

posted @ 2014-03-15 19:36  Richaaaard  阅读(519)  评论(0编辑  收藏  举报