foo()和foo(void)之间的区别 [英] Difference between `foo()` and `foo(void)`

查看:184
本文介绍了foo()和foo(void)之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,这两个函数声明之间有什么区别?

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

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

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

此处,您可以找到该问题的答案,但 C/C ++ 除外.在这些语言中,两种声明样式的存在是完全有意义的.

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.

但是 Java 的目的是什么?

推荐答案

后一种声明在Java中是非法的.您不能声明这样的方法.您应该会收到这样的错误:

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.

这篇关于foo()和foo(void)之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆