-1

I tried below and they don't work

fun get (headers: Array<String>= emptyArray())
fun get (headers: Array<String>= null)
fun get (headers: Array<String>= arrayOf(""))
fun get (headers: Array<String>= arrayOfNulls(1))

I checked the links below What's the Kotlin equivalent of Java's String[]?

https://kotlinlang.org/docs/functions.html

  • What error message are you getting? `emptyArray()` and `arrayOf("")` should work just fine. `null` works if you declare the argument as nullable (`Array?`), and `arrayOfNulls(1)` works if you declare the *contents* of the array as nullable (`Array`). – dnault May 04 '21 at 19:37

1 Answers1

3

Your first line should be fine if you put a space between > and =.

fun get (headers: Array<String> = emptyArray())
Tenfour04
  • 83,111
  • 11
  • 94
  • 154
  • I can't believe a space also play such a important role in Kotlin like Python. Google developers really think high of the space. –  May 04 '21 at 20:34
  • 2
    @Shui This is one of those rare cases when a space is significant, as `>=` is an operator in itself. – gidds May 04 '21 at 22:57
  • 1
    @Shui Kotlin is developed by JetBrains, not Google. – Alexey Romanov May 05 '21 at 07:42