Suppose there is a requirement to use a particular generic interface, but the situation does not require making use of one of the generic parameters.
Let’s say I need a Callable<T> (which must return a T from its call() method), but on this occasion I don’t need the return result, I just want to submit some code to an ExecutorService to “do something”
What’s the best option for the type T?
You can use the special
Voidtype:The
returnstatement is required to exit the method. The only value which the compiler accepts isnull. Quite handy!