Alex Rivera | Logout

Uses for the Java Void Reference Type?

Asked 2009-03-13T18:08:43.480
176

There is a Java Void -- uppercase V-- reference type. The only situation I have ever seen it used is to parameterize Callables

final Callable<Void> callable = new Callable<Void>() {
            public Void call() {
                foobar();
                return null;
            }
        };

Are there any other uses for the Java Void reference type? Can it ever be assigned anything other than null? If yes, do you have examples?

Edit
Report

1 Answer

22

Given that there are no public constructors, I would say it can't be assigned anything other than null. I've only used it as a placeholder for "I don't need to use this generic parameter," as your example shows.

It could also be used in reflection, from what its Javadoc says:

The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void.

answered 2009-03-13T18:12:00.447

Your Answer