Why collection literals?

前端 未结 11 856
无人及你
无人及你 2020-12-29 04:09

From the various online articles on Java 7 I have come to know that Java 7 will be having collection literals1 like the following:

List

        
11条回答
  •  执念已碎
    2020-12-29 05:02

    Answer to question 2:

    final List piDigits = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9];
    

    gives you an immutable list.

    The whole idea of this proposal that the subtype cannot be specified. The compiler chooses a suitable implementation depending on the collection on the right-hand side.

    Read the details here: Proposal: Collection Literals

    Answer to question 1: yes it would have. It's a matter of style.

提交回复
热议问题