构造函数在Java中返回什么? [英] What does a constructor return in Java?

查看:227
本文介绍了构造函数在Java中返回什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在关于这个主题的帖子后,我发现自己有点困惑。
所以我再次问这个:

After going on the post on this topic I found myself little confused. So again I am asking this:


Java构造函数是否返回任何值?

"Does Java constructor returns any value?"

我的书说它们不能返回值,但是我的教授说他们可以并且他们总是这样做。

My books say they can't return a value, but my professor says they can and they are always doing so.

由于控件需要转移给某些有价值的人无效吗?

As the control needs to be transferred to someone with some value either void?

推荐答案

这有点令人困惑:构造函数确实没有返回值;它是运营商 new 。但是,构造函数总是与 new * 一起使用,因此看起来总是返回一个值。



* 这是一个小小的简化:你可以使用没有 new 的构造函数反射。但是,相同的机制将起作用。

This is a little confusing: constructors indeed do not return a value; it is operator new that does. However, constructors are always used with a new*, so it looks like they always return a value.


* This is a slight simplification: you can use a constructor without new if you go through reflection. However, the same mechanisms will be in play.

这篇关于构造函数在Java中返回什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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