val shoppingList = arrayOf("catfish", "water", "tulips", "blue paint")
What is wrong with square bracket syntax? (rant over).
EDIT: I suppose it's consistent with other syntax e.g. listOf() etc.
val shoppingList = arrayOf("catfish", "water", "tulips", "blue paint")
What is wrong with square bracket syntax? (rant over).
EDIT: I suppose it's consistent with other syntax e.g. listOf() etc.
Well yeah, except it's really that Kotlin does not have array literals at all, arrayOf is just a variable-arity function.
For example:
let x = [1, 2, 3] // produces Array
let y: MyType = [1, 2, 3] // produces MyType
f([1, 2, 3]) // produces whatever type f() takesI'll pick short forms all the time: lists with (), dictionaries/hashes with {}.
In practice, it's something I stopped caring about within the first hour.
Then again, mikeash's comment pitches a more interesting idea: [] as generic collection literal syntax that depends on inference / annotation to pick a concrete implementation. Best of both worlds. I'd just remove the Array default.
val shoppingList = Seq("catfish", "water", "tulips", "blue paint")
"Foo" to "Bar"
Is also nonsensical. What's wrong with ':'?
The to method constructs a Pair object from its arguments, so
"Foo" to "Bar"
is just a prettier way of writing: Pair("Foo", "Bar")
The mapOf function (which is just a normal function) takes a variable number of Pair objects as parameters.It is more ugly for arrays but much more helpful for other things. And it also make sense with the lists as you said.