# New(?) idea for collection literals

**URL:** <https://discuss.kotlinlang.org/t/new-idea-for-collection-literals/30728>\
**Category:** Language Design\
**Created:** [August 21, 2025, 7:53pm UTC](https://discuss.kotlinlang.org/t/new-idea-for-collection-literals/30728 "2025-08-21T19:53:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjishults](https://avatars.discourse-cdn.com/v4/letter/b/c0e974/32.png) [@benjishults](https://discuss.kotlinlang.org/u/benjishults)\
**Post date:** [August 21, 2025, 7:53pm UTC](https://discuss.kotlinlang.org/t/new-idea-for-collection-literals/30728/1 "2025-08-21T19:53:54Z")

</div>

Typing this out from my phone so I haven’t tested the idea thoroughly but thought the idea maybe spark a good discussion.

Collection literals will only be available when there is a “CollectionBuilder” in context. For example:

```kotlin
fun interface ListBuilder<I, out T: List<I>> {
    operator fun buildList(varargs elements: I): T
}

```

This would allow code looking something like this:

```kotlin
    val list = with(ArrayListBuilder) {
        [1, 2, 3]
    }

```

Of course, Kotlin let’s us bring things into context in a lot of ways that are prettier than this, including context parameters or by implementing the interface.

As the language progresses (e.g. with truly immutable collections) more implementations of these interfaces can be added.

In this way, the notation is flexible and user-extensible. It would also always be clear (from the context) what is meant by the notation.

Sorry if this isn’t original. If it’s been discussed already, maybe someone can comment here with a link.

---

<div class="post-metadata">

**Author:** ![benjishults](https://avatars.discourse-cdn.com/v4/letter/b/c0e974/32.png) [@benjishults](https://discuss.kotlinlang.org/u/benjishults)\
**Post date:** [August 21, 2025, 9:00pm UTC](https://discuss.kotlinlang.org/t/new-idea-for-collection-literals/30728/2 "2025-08-21T21:00:30Z")

</div>

Here is Brian Goetz talking about something similar in an imagined Java future: [https://youtu.be/Gz7Or9C0TpM?si=otGkrxApa4bFmxuX](https://youtu.be/Gz7Or9C0TpM?si=otGkrxApa4bFmxuX)

---

<div class="post-metadata">

**Author:** ![Skater901](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/skater901/32/10163_2.png) [@Skater901](https://discuss.kotlinlang.org/u/Skater901)\
**Post date:** [August 22, 2025, 8:47am UTC](https://discuss.kotlinlang.org/t/new-idea-for-collection-literals/30728/3 "2025-08-22T08:47:53Z")

</div>

Tbh I actually don’t know why Kotlin doesn’t have collection literal syntax. I assume there’s a good reason for it, I just don’t know what that reason is.

---

<div class="post-metadata">

**Author:** ![Landei](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/landei/32/9407_2.png) [@Landei](https://discuss.kotlinlang.org/u/Landei)\
**Post date:** [August 22, 2025, 8:20pm UTC](https://discuss.kotlinlang.org/t/new-idea-for-collection-literals/30728/4 "2025-08-22T20:20:29Z")

</div>

At least there is a KEEP: [KEEP/proposals/collection-literals.md at bobko/collection-literals · Kotlin/KEEP · GitHub](https://github.com/Kotlin/KEEP/blob/bobko/collection-literals/proposals/collection-literals.md)
