开发者

In Java why would one want to put the brackets in front of the name of an aray?

开发者 https://www.devze.com 2023-01-03 06:10 出处:网络
I\'ve been told that int[] numbers and int numbers[] are equivalent. I\'ve only ever seen the former though. What impetus is there,开发者_开发百科 if ever, to write the latter? None.It\'s ju

I've been told that

int[] numbers 

and

int numbers[] 

are equivalent. I've only ever seen the former though. What impetus is there,开发者_开发百科 if ever, to write the latter?


None. It's just a legacy from C syntax. However, it should be noted that C and Java arrays are very different. Java arrays are more like a malloc-allocated pointer with a length field.


Doesnt really matter, but, my personal preference is for int[] numbers as it more logically follows the class instance_name pattern.

After all you are really delcaring an "array of integers" called "numbers", the second form is slightly misleading as its more of declaring "an integer" called "numbers" oh and by the way its actually an array of "numbers".


just becoz of- the way earlier we used to declare in C. two options are available...chose as per ur convenience. No big deal, java provided new way of declaring array & remained the old way of declaring array also. Full freedom for programmer....cool stuff. no confusion at all.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号