Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the point of java.lang.Void.

 
Mike Forsberg
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this is the correct place for this question, but here it is.
While studying for the SCJP, my group came across the java.lang.Void class. We understood that it represents the primative return type Void. What is its purpose? Is it only used as a place holder for reflection calls???
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the JavaDoc:
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void.
It's there so you can do
Class voidClass = void.class;
for completeness with the other Class literals.
Now, *why* you would need to do this, I don't know. But someone in java-land thought it was important, so there ya go.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's part of reflection. The method Method.getReturnType() returns a Class type. The Void class holds a Class object representing the void type.
[ April 03, 2002: Message edited by: Thomas Paul ]
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
void is not a primitive type. Please refer to the following discussion:
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=013732
 
Mike Forsberg
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank's I guess I should search before asking a question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic