The difference between `foo ()` and `foo (void)`

In Java, is there a difference between these two function declarations?

public void foo() {/*...*/} public void foo(void) {/*...*/} 

Here you can find the answer to this question, but for C / C ++ . In these languages, he fully understands the existence of both styles of declaration.

But what is the point of this in Java ?

0
java methods
Nov 21 2018-11-11T00:
source share
2 answers

The last declaration is illegal in Java. You cannot declare such a method. You should get this error:

 Test.java:8: error: <identifier> expected public void foo(void) {/*...*/} ^ 1 error 

Thus, not only does it make no sense - you simply will not find valid code that tries to use this style.

+17
Nov 21 '11 at 19:33
source share

You can try

 public void foo(Void v) {/*...*/} 
+1
Dec 31 '13 at 2:26
source share



All Articles