用逗号结尾Java数组初始化列表 [英] Java array initialization list ending with a comma

查看:114
本文介绍了用逗号结尾Java数组初始化列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

逗号,在数组初始化列表中使用可能最终在C列表项目分离,这是在的由Kernighan的&C程序设计语言第2版功放提到;里奇的。

The comma , items separator used in an array initialization list may end the list in C, this is mentioned in The C Programming Language 2nd ed by Kernighan & Ritchie .

例如

  int c[] = { 1, 2, 3, };

这是在方便的时候名单很长,和一个不希望有改变/检查previous行添加项目时

This is convenient when the list is long, and one doesn't want to have to change/check the previous line when adding items

  long long c[] = { 
                    22342342344,
                     4324234234,
                    12312311111,
                   };

但在Java中,我可以观察到两种不同的行为:

在Eclipse中,结束被接受,而Maven的编译器插件某些版本的抱怨,并抛出一个编译错误。

However in Java I could observe two different behaviors:
In Eclipse, the ending , is accepted while some versions of the maven compiler plugin complain and throw a compilation error.

不过,我没有找到这个奇点在任何提及的弗拉纳根的Java 的书。

However, I didn't find any mention of this singularity in the Flanagan's Java book.

什么是关于初始化项目后结束逗号官方规则?

它是推荐的的使用呢?

What is the official rule regarding an ending comma after the initialization items?
Is it recommended not to use it?

推荐答案

规范的第10.6节明确地说,尾随逗号是允许(和忽略):

Section 10.6 of the spec explicitly says that a trailing comma is allowed (and ignored):

一个结尾逗号可以在数组初始化的最后EX pression后出现,将被忽略。

A trailing comma may appear after the last expression in an array initializer and is ignored.

链接

这篇关于用逗号结尾Java数组初始化列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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