加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – On void返回类型

发布时间:2020-12-14 05:20:06 所属栏目:Java 来源:网络整理
导读:如果需要返回一个Void类型,Javadoc描述为 A class that is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void. 为什么以下仍然需要返回null? public Void blah() { return null; // seems
如果需要返回一个Void类型,Javadoc描述为

A class that is an uninstantiable placeholder class to hold a
reference to the Class object representing the Java keyword void.

为什么以下仍然需要返回null?

public Void blah() {
    return null; // seems to always want null
}

解决方法

Void是像任何其他类的类,所以返回Void的函数必须返回引用(如null).实际上,Void是最终的,并且不可抗拒,这意味着null是返回Void的函数唯一可以返回的值.

当然,public void blah(){…}(小写v)不必返回任何东西.

如果您想知道Void的可能用途,请参阅Uses for the Java Void Reference Type?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读