# Plans for collection literals?

**URL:** <https://discuss.kotlinlang.org/t/plans-for-collection-literals/2049>\
**Category:** Uncategorized\
**Created:** [October 18, 2016, 11:26am UTC](https://discuss.kotlinlang.org/t/plans-for-collection-literals/2049 "2016-10-18T11:26:29Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![alanfo](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@alanfo](https://discuss.kotlinlang.org/u/alanfo)\
**Post date:** [August 11, 2017, 10:01am UTC](https://discuss.kotlinlang.org/t/plans-for-collection-literals/2049/13 "2017-08-11T10:01:20Z")

</div>

Given that array literals have already been introduced for annotations (in 1.2 M1), for consistency I’d have thought that arrays should be the default and not lists.

If one of the main reasons for them is to save typing, then to my mind the most sensible plan would be:

1. If the literal contains elements of one of the primitive types, then a dedicated array for that type should be assumed. So [1, 2, 3] would be an `IntArray` and [‘a’, ‘b’, ‘c’] would be a `CharArray`.

2. In all other cases the generic array type, `Array<T>`, should be the default.

As for the other collection types, couldn’t the type of these just be deduced from the context? So, for example:

```auto
val ls: List = [1, 2, 3] // List<Int>
val ms: MutableList = ["a", "b", "c"] // MutableList<String>
val l2d: List = [[1, 2], [3, 4] ] // List<IntArray>
val a2d = [['a', 'b'], ['c', 'd'] ] // Array<CharArray>

val aSet: HashSet = [1, 2, 3] // HashSet<Int>
val aList: LinkedList = ["x", foo(), *bar()] // LinkedList<Any?> possibly 
val aMap: TreeMap = [1 to "One", 2 to "Two"] // TreeMap<Int, String>  

```

or, if you have a function, say:

```auto
fun someFun(h: HashSet<Int>) {
    // do something
}

```

you could call it with a line such as:

```auto
someFun([1, 2, 3])

```

Incidentally, I should mention that initially I was against collection literals but I’ve come around to the idea partly because it now looks inevitable but mainly because I see it as the only way to have a more compact notation for multi-dimensional collections.

---

_[View the full topic](https://discuss.kotlinlang.org/t/plans-for-collection-literals/2049)._
