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
  • 3,031
  • 2
  • 26
  • 46

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,421,763
  • 867
  • 9,128
  • 9,194
1

You can try

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