简体   繁体   English

构造函数可以使用类似Java的方法返回数据类型吗?

[英]Can constructor return data types in java like methods?

I have a question in java object oriented programming. 我在Java面向对象编程中有一个问题。

Can constructors return data types like methods in java? 构造函数可以返回Java中的方法之类的数据类型吗?

Constructors always return an object of the class they belong to, just like specified in the Java Language Specification . 构造函数总是返回其所属类的对象,就像Java语言规范中所指定的那样。

Unlike method return types, the constructor "return type" is implicit. 与方法返回类型不同,构造函数“返回类型”是隐式的。

Not according to the documentation here 不符合此处的文档

Constructor declarations look like method declarations—except that they use the name of the class and have no return type 构造函数声明类似于方法声明,只是它们使用类的名称并且没有返回类型

From the docs 来自文档

Constructor declarations look like method declarations—except that they use the name of the class and have no return type . 构造函数声明看起来像方法声明,只是它们使用类的名称并且没有返回类型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM