Java Void type without?


I just got a null pointer waring because the use of Void in a generic callback function.

Let’s say I’m using AsyncTask<Void, Void, Void> this would inherently be an error which is triggered when onPostExecute is executed since Void will always be null.

It would be great if a warning could be triggered when using Void without ? since this would always be an error, alternatively being able to drop the argument in the callbacks which are Void completely like

override fun onPostExecuteEx(dummy: Void?)  {}

override fun onPostExecuteEx()  {}

What do you think?

Also the automatic code converter should always add ? when converting java code to kotlin code for Void types


I’m not sure whether you need Void for Java compatibility here, but the Kotlin way would be to use Unit instead.


Looks like Void in java is more like Nothing in Kotlin (than Unit).
Void? has only one instance - null (same with Noting?).
Void itself has no instances at all (same with Nothing).
Unit - has only one value too Unit, but Unit? has two values (null and Unit)