arrayOf unnatural

Actually this discussion conflates two issues which are actually separate: the syntax for using arrays in annotations and the syntax for collection literals.

Inside annotations, arrays are a special case because there is a very restricted set of data types allowed for use as annotation parameters. It’s obvious that the current situation with arrays in annotations in Kotlin is significantly more ugly than Java, because array parameters are used commonly and require using arrayOf() which is not required in Java. This is what KT-11235 is talking about. Addressing this issue may, or may not, require introducing some kind of syntax for collection literals.

Outside of annotations, arrays are most definitely not a special case and we’re most definitely not going to introduce a syntax which will allow you to create only arrays but not other kinds of collections.

You say that you’re asking for something which is very very small - but it is not, because there’s a very limited amount of characters that can be used as part of the language syntax without making the language more ugly. If we use the [1, 2, 3] syntax for array literals as Java does, it makes this syntax permanently unavailable for other constructs which we may consider more important to include in the language (the most obvious one is literals for other kinds of collections such as lists).

4 Likes