0

In Java, is there any difference between this two function declarations?

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

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

Here you can find the answear to this question but for C/C++. In these languages it makes totally sense the existance of both declaration styles.

But what is the point of this in Java ?

Community
  • 1
  • 1
eversor
  • 2,867
  • 2
  • 24
  • 44

2 Answers2

17

The latter declaration illegal in Java. You can't declare a method like that. You should get an error like this:

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

So not only is there no point - you simply won't find valid code which attempts to use this style.

Jon Skeet
  • 1,335,956
  • 823
  • 8,931
  • 9,049
1

You can try

public void foo(Void v) {/*...*/}
justjavac
  • 505
  • 2
  • 8
  • 26