This week's book giveaways are in the iOS and Features new in Java 8 forums.
We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Void Wrapper Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Void Wrapper Class" Watch "Void Wrapper Class" New topic

Void Wrapper Class

Abhimanyu Kumar

Joined: Nov 05, 2004
Posts: 12
Has anyone of you used the Void wrapper class ? I read that it does not wrap any primitive data type but it is used to represent void keyword. I'm curious to see some code using this class

Thanks In Advance,

"Where there's a will, I want to be in it."
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

The only place it's used is in the Java Reflection API. There's a class java.lang.reflect.Method, which Java uses to represent a Java method. You can ask a Method object what its return type is. It answers by returning a Class object. The Void class contains the constant Void.TYPE which is used to represent "void" in this context. That's it -- you're actually not allowed to create an instance of Void, so there's really nothing else this class can be used for.
[ November 05, 2004: Message edited by: Ernest Friedman-Hill ]

[Jess in Action][AskingGoodQuestions]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I don't think I've ever written a program that uses it. The primary use I see, though, is reflection. If you are interested in exploring this further, you should learn more about the Java Reflection API. I'm sure you can also use the Search utility here at the Big Moose Saloon to find previous discussions on reflect.



Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: Void Wrapper Class