有没有任何区别"对象[]×"和"对象x [] QUOT ;? [英] Is there any difference between "Object[] x" and "Object x[]"?

查看:147
本文介绍了有没有任何区别"对象[]×"和"对象x [] QUOT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更新Java中的遗留code的基础,我发现这样一行:

 对象ARG [] = {新的整数(20),新的整数(22)};

这行逮住我的注意,因为我习惯了这种code的:

 对象[] = ARG {新的整数(20),新的整数(22)};

数组的内容在这里并不重要。我很好奇括号中的变量名与旁边的类名括号旁边。我在Eclipse中尝试(使用Java 5)和两条线是有效的编译器。

有这些声明有何区别?


解决方案

两者都是法律和双方的工作。但建议数组的名字前面放置[]。

的Javadoc :


  

您也可以放置在方括号中的数组名称后面:


 浮动anArrayOfFloats []; //这种形式是不鼓励


  

然而,习惯不鼓励这种形式;括号标识阵列类型和应与类型名称出现。


I was updating a legacy code base in Java and I found a line like this:

Object arg[] = { new Integer(20), new Integer(22) };

That line catched my attention because I am used to this kind of code:

Object[] arg = { new Integer(20), new Integer(22) };

The content of the array isn't important here. I'm curious about the brackets next to the variable name versus the brackets next to the class name. I tried in Eclipse (with Java 5) and both lines are valid for the compiler.

Is there any difference between those declarations?

解决方案

Both are legal and both work. But placing [] before the array's name is recommended.

From Javadocs:

You can also place the square brackets after the array's name:

float anArrayOfFloats[]; // this form is discouraged

However, convention discourages this form; the brackets identify the array type and should appear with the type designation.

这篇关于有没有任何区别"对象[]×"和"对象x [] QUOT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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