# Shorthand for Collection Construction

**URL:** <https://discuss.kotlinlang.org/t/shorthand-for-collection-construction/28003>\
**Category:** Language Design\
**Created:** [January 23, 2024, 8:49am UTC](https://discuss.kotlinlang.org/t/shorthand-for-collection-construction/28003 "2024-01-23T08:49:03Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![gidds](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/gidds/32/10865_2.png) [@gidds](https://discuss.kotlinlang.org/u/gidds)\
**Post date:** [January 24, 2024, 4:48pm UTC](https://discuss.kotlinlang.org/t/shorthand-for-collection-construction/28003/2 "2024-01-24T16:48:14Z")

</div>

What sort of collection do you want to construct?

A mutable one, or an immutable one? A List, or a Set, or simply a plain Collection? Map types too? Does it need to be concurrent? What element type should it have? (You can’t necessarily infer the element type from the arguments; there might not _be_ any arguments, and even if there were, you might want a supertype, e.g. to ensure it’s nullable.) What sort of performance should it have? (E.g. how should it trade off memory for speed? Should it be optimised for small collections, or to improve the worst case?)

There’s no single right answer to all those questions — so you’d either have to make a single choice that doesn’t work for some cases, or you’d have to support some options (which would mean its syntax wouldn’t be significantly shorter than the existing 6-character `listOf`).

This idea [has](https://discuss.kotlinlang.org/t/plans-for-collection-literals/2049) [been](https://discuss.kotlinlang.org/t/kotlin-language-feature-requests/1001) [discussed](https://youtrack.jetbrains.com/issue/KT-43871) [many](https://discuss.kotlinlang.org/t/collection-literals-support-outside-annotation/9028) [times](https://discuss.kotlinlang.org/t/arrays-2-0-multiple-varargs-and-collection-literals/4951/3) [before](https://discuss.kotlinlang.org/t/create-array-as-1-2-3-and-maps-as-a-10/22506), but although it’s attractive, there’s not been any consensus about how to do it with enough benefit to [justify](http://stronglyemergent.com/blog/2013/negative-100-points/) the extra complexity it would bring to the language.

(Note that many of the languages that _do_ have collection literals lack Kotlin’s flexibility with collection types, and so aren’t really comparable. Also, I suspect the simple paren syntax you suggest would either have to be restricted to immediately after `=`, which would prevent lots of desirable usages, or it would conflict with existing uses of parens for grouping etc.)

And `listOf()` isn’t that verbose, is it? (I remember the old days, in Java ≤ 7, when you’d need a whole block of code to create an `ArrayList`, call `add()` for each item, and then use the result…)

---

_[View the full topic](https://discuss.kotlinlang.org/t/shorthand-for-collection-construction/28003)._
