void not the actual type of return (data)! void says no result. Thus, you cannot return a value in a method that declared void , even if the method you call is also declared void .
I have to admit that this will be a good shortcut, but that’s not how everything works :-)
One more thought: if you were allowed, void will become both a data type and the only possible value of this data type, since return x; defined as the return value of x to the caller. So return void; will return void caller - impossible by definition.
This is a different value for null , for example, since null is a valid value for reference types.
source share