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

后端 未结 7 1013
-上瘾入骨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:52

    From Java 6 API docs:

    public boolean isPrimitive() - Determines if the specified Class object represents a primitive type.

    Returns: true if and only if this class represents a primitive type

    I checked for myself:

    void.class.getName() // void (OK)
    void.class.isPrimitive() // true (??)
    Void.class.getName() // java.lang.Void (OK)
    Void.class.isPrimitive() // false (OK)
    

    Is it bug ? I know that void is not primitive type (I think it is just keyword), but why void.class.isPrimitive() returns true ?

    edit: I think it should be clarified, so I suggested java:doc bug 7019906. In my opinion it should be:

    public boolean isPrimitive() - Determines if the specified Class object represents a primitive type or a keyword void.

    Returns: true if and only if this class represents a primitive type or a keyword void.

    0 讨论(0)
提交回复
热议问题