my dog learned polymorphism
The moose likes Java in General and the fly likes What is the point of java.lang.Void. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "What is the point of java.lang.Void." Watch "What is the point of java.lang.Void." New topic

What is the point of java.lang.Void.

Mike Forsberg

Joined: Apr 03, 2002
Posts: 3
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

Joined: Jan 07, 2002
Posts: 2205
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.

SCJP 1.4
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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 ]

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
void is not a primitive type. Please refer to the following discussion:

[Blog] [Blogroll] [My Reviews] My Linked In
Mike Forsberg

Joined: Apr 03, 2002
Posts: 3
Thank's I guess I should search before asking a question.
I agree. Here's the link:
subject: What is the point of java.lang.Void.
It's not a secret anymore!