Difference between `foo()` and `foo(void)`

前端 未结 2 588
长情又很酷
长情又很酷 2021-01-29 02:18

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

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

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

Here you

2条回答
  •  走了就别回头了
    2021-01-29 02:36

    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:  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.

提交回复
热议问题