Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Void class?

 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends

Please giude me the concept of void class in java.lang package..... with example
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's used to express the "void" keyword. I use it with the java.util.concurrent.Callable interface, to say that I'm not expecting any returned value from the executed thread.
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:It's used to express the "void" keyword. I use it with the java.util.concurrent.Callable interface, to say that I'm not expecting any returned value from the executed thread.


hi friend ...... as you told it is used to express the void keyword... then what is the difference between keyword void and class void...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my example, you need a Class to be used as a generic type. "void" is just a keyword, it cannot be used for generic types. You cannot use "new Callable<void>". To correct this, you must use the Void class instead.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, Void.TYPE is what will be returned from Method.getReturnType() for methods that return nothing (void). That's probably where the entire class was originally created for, since generics didn't exist until Java 5.0, but Void exists since Java 1.1.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic