Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

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?

1 Answer

0 votes
by (46k points)
Void has become convention for a generic argument that you are not interested in. There is no reason why you should use any other non-instantiable type, such as System.

It is also often used in for example Map values (although Collections.newSetFromMap uses Boolean as maps don't have to accept null values) and java.security.PrivilegedAction.

Related questions

0 votes
1 answer
asked Nov 12, 2019 in Java by Anvi (10.2k points)
0 votes
4 answers
0 votes
3 answers
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...