I've noticed eclipse JDT uses void
as a primitive type. Can this be considered correct?
Primitive types are the most basic data types available within the Java language. There are 8: boolean , byte , char , short , int , long , float and double . These types serve as the building blocks of data manipulation in Java. Such types serve only one purpose — containing pure, simple values of a kind.
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void.
Examples of non-primitive types are Strings, Arrays, Classes, Interface, etc. You will learn more about these in a later chapter.
Any method declared void doesn't return a value. It does not need to contain a return statement, but it may do so.
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 http://java.sun.com/docs/books/jls/third_edition/html/statements.html#5989 (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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With