为什么 Java 数组声明使用大括号? [英] Why do Java array declarations use curly brackets?

查看:95
本文介绍了为什么 Java 数组声明使用大括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么 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.

很久以前,人们已经习惯了这种约定C.我很确定它在 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 数组声明使用大括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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