In Java, can “void” be considered a primitive type?

后端 未结 7 1014
-上瘾入骨i
-上瘾入骨i 2021-01-17 10:21

I\'ve noticed eclipse JDT uses void as a primitive type. Can this be considered correct?

7条回答
  •  一生所求
    2021-01-17 10:49

    No void is not a primitive type. It is simply a keyword to indicate a method has no return value. The closest you can come is the java.lang.Void class, which from the Javadocs is described as:

    The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void.

    The presence in the JDT is merely to build the ASTs for the code. If you look at the field value description in the same docs it says:

    Type code for the primitive type "void". Note that "void" is special in that its only legitimate uses are as a method return type and as a type literal.

提交回复
热议问题