#java should allow return void. Now the following proxy won't compile. The keyword "return" needs to be removed/added when iterating the method return type:
@Override
public void m(String arg) {
return delegate.m(arg);
}
Furthermore, while at it, why not make all statements expressions?
@Override
public void m(String arg) {
return delegate.m(arg);
}
Furthermore, while at it, why not make all statements expressions?
Comments
I can only imagine it would be equivalent to
f();
k();
but less readable.
BTW, with the JDK you can have the same InvocationHandler for both void and non-void methods.
void f() {...}
int k() { ... }
the 2nd one meaning: int k(void) { ... }
if you accept passing void as a value the expression k(f()) is perfectly legal. And it is an equivalent to calling f() then k(), but less readable.
int k(void) { ... } to be allowed to pass void as a parameter, or if you allow it even for int k(/*empty*/) { ... }.
Making void a normal type just leads to lots of nonsense.
And if you accept void* or such, you should accept adding members to objects at runtime too, otherwise you lose type safety without gaining flexibility.
And if you accept adding members at runtime, you get JavaScript, which is a beautiful language.
We just don't wish that for Java.
What would be the value of a for() as an expression?
It is very important for humans to discernate actions from objects, verbs from nouns. Making statements and expressions one wouldn't help.
void m() may have no return statement, a return without value, or return a statement.
vvoid m() may have no return, or a return without value, but not return a statement.
xvoid m() can't even contain a return.
evoid m() MUST contain a return without value
svoid m() MUST return a statement
fvoid m() MUST return a for(), ivoid m() must return an if(), etc.
The ultimate finetyping 😃
function m() {
for(...) { doSomething } //repeat something
return; //then end the function
}
// I write A then B but the programm executes B then A
function m() {
return for(...) { doSomething }
}
This is not at all easy to follow. We should not reinforce this kind of code knoting.
writing order: f,x,g,y,z
exec order: x,y,g,z,f
that's just sick.
We shouldn't allow that kind of mixing for even more parts of the proglangs.
I have done it / Ich habe es gemacht / Je l'ai fait
and that's why we don't use polonese reverse notation at school and we write f(a,b) instead of (a,b)f. But natural languages are not meant to be executed...