问题描述
我想知道为什么Java数组声明使用大括号而不是标准括号。如图所示。我想这可能需要进一步理解大括号,但现在我已经专门讨论了这个问题。
I would like to know why Java array declarations use curly brackets as opposed to the standard parenthesis. As illustrated here. I imagine this may take further understanding of curly brackets in general, but this specifically is on my agenda right now.
Object[] tableHeaders = {"Cars","Trucks","Tacos"};
这是正确的,而不是。
Object[] tableHeaders = ("Cars","Trucks","Tacos");
推荐答案
圆括号通常表示集合和集合,而括号通常表示C语言中的参数。
Curly brackets usually denotes sets and ensembles while parenthesis usually denotes parameters in C-like languages.
很久以前,人们已经习惯了。我很确定它在Java中以这种方式工作,以保持与旧语言的某种语法一致性。
A long time ago, people got used to having this kind of convention with C. I'm pretty sure that it works this way in Java to keep some kind of syntax consistency with older languages.
这篇关于为什么Java数组声明使用大括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!