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

前端 未结 2 589
长情又很酷
长情又很酷 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: <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.

    0 讨论(0)
  • 2021-01-29 02:36

    You can try

    public void foo(Void v) {/*...*/}
    
    0 讨论(0)
提交回复
热议问题