Plans for collection literals?

Yes, why not simply use parenthesis?! The implementation would be shockingly simple:

inline fun <reified T> a(vararg items: T): Array<T> = arrayOf<T>(*items)

Usage:

a(1, 2, 3) // Array
s("a", "b", "c") // Set
m("a" to 1, "b" to 2) //Map

This is concise, at least as readable as special literal syntax and is extensible. Plus it is only a simple library function. However one could simply import the existsing function with as under a different name today … But I think some standardization would be helpful if we want to have short syntax for collections.

3 Likes