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

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


I find that, in cases like this, you can’t beat going to the Java Language Specification. It is pretty clear about the fact that void is not a primitive.

First off, void is not in the list of primitive types. Later on, the JLS explicitly states:

the Java programming language does not allow a “cast to void” — void is not a type (emphasis mine)

Furthermore, void appears in the list of keywords, not the list of literals.

The reason that you saw what you did was explained nicely by Michael Borgwardt.

So, to answer your title: no. In Java, void cannot be considered a primitive. To answer your body: yes, the Eclipse JDT code is correct for what it needs to do.

Leave a Reply

Your email address will not be published. Required fields are marked *