Search code examples
javalanguage-design

Why is void keyword not used as method argument?


The void keyword is only used as a return type to indicate that a method does not return a value. But why can't void be used as a formal parameter in method definition to indicate that it does not accept any arguments, like:

void fun(void){
    ...
}

Solution

  • It's unnecessary. If a method does not have arguments, specifying an empty argument set () is sufficient.