void
is not an actual return (data)type! void
says there is no result. So you can not return a value in a method that's declared void
even though the method you're calling is also declared void
.
I must admit it would be a nice shortcut, but it's not how things work :-)
Just an additional thought: If what you want was allowed, void
would become both a data type and also the only possible value of that data type, as return x;
is defined as returning the value x
to the caller. So return void;
would return the value void
to the caller - not possible by definition.
This is different for null
for example, as null
is a valid value for reference types.