There is something called Type System which is a set of rules that determine how the data will behave and what you can do with them. It is based on type theory .
So all language data structures are somehow based on these rules set by the type system of the language you are using.
Then the rules for void
are special. Does it make sense to be like this? I think it does. It would make sense for him to be a normal guy. I would do it. Every decision has its implication.
A return
can be used without anything or can be used with an expression. It can only be used if the method signature indicates that it should not return something (with void
). If the method is void
it can not return something, and the syntax used is returning something.
Then you will say, "is not returning something, the method called is void
and void
indicates that there is something there", or say "is returning void
to something expecting void
. but this is circumstantial, it may change.But the worst is that it implies that something is being returned since by beating the eye% cos it seems that there is something there, only further investigation will indicate that it is even suitable. p>
Furthermore this is a matter of consistency, in several places you can not use it so, why would you use it in return algumacoisa
? What gain do you expect to have?
So it has been defined that any method that is return
can only be called where a statement is expected and not where an expression is expected. This is more readable and works fine with no downside:
Test1();
return;
Want to in a row?
Test1(); return;
Any feature needs to be paid. There has to be a justification for its adoption, it has to give a real benefit and not charge anything significant.
Informally we even say "method returns void
", but this is conceptually wrong.
Other languages may be different.
You have proposal to allow this , but it was not very well accepted. Another .
Canonical Response .