• Post Reply Bookmark Topic Watch Topic
  • New Topic

Void Class  RSS feed

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Freinds,

How Void wrapper class denotes the Class object as representing the keyword void.

Regards,
Hari Krishna.
 
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This topic is definitely not on any SCJP exam, so I''m moving this to Java in General - Intermediate.
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only reason that Void exists is so that when you call, for example, java.lang.reflect.Method.getReturnType() on a Method object representing a method that returns void, there's something sensible to return. You can't create instances of this type -- only the Class object itself has any value.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I can tell, the only reason the class Void exists is so that there will be an instance of the Class class which corresponds to the void type - namely, Void.class. And the only reason we ever might need that seems to be for reflection - specifically, for the getReturnType() method in Method. Otherwise, how would we be able to discover that a given method returns void? Well, they probably could have had getReturnType() return null instead (and document that fact) - but this works too.

If anyone knows of any other reason why the Void class exists, please share.

And by the way, a pox on EFH for stealing my question.
[ November 30, 2005: Message edited by: Jim Yingst ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!