方括号是什么意思?在 Java 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26538048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what do the square brackets mean? in Java
提问by Supernaturalgirl 1967
What does it mean when their are square brackets in front of double
. For example double[]
and is there any special way to use the return function when using them in a method.
当它们前面是方括号时是什么意思double
。例如double[]
,在方法中使用返回函数时是否有任何特殊的方法来使用它们。
For Example:
例如:
public double[] MethodName(){
}
What is the type of the return value?
返回值的类型是什么?
回答by 12341234
Square brackets []
would indicate an array. In your case of code:
方括号[]
将表示一个数组。在您的代码情况下:
public double[] MethodName(){
....
}
public double[] MethodName(){
....
}
You have a public method MethodName
which returns an array. Double indicates what type the array is, i.e. stores an array of objects of type double.
您有一个MethodName
返回数组的公共方法。Double 表示数组是什么类型,即存储一个double 类型的对象数组。
EDIT: Forgot about answering your return question. But for your line of code, MethodName
would return an array of type double (which would depend on the implmentation inside the method body). Hope that helps (I'm new to Java too; climbing the SO rep ladder)
编辑:忘记回答您的退货问题。但是对于您的代码行,MethodName
将返回一个 double 类型的数组(这取决于方法体内的实现)。希望有所帮助(我也是 Java 新手;爬上 SO 代表阶梯)