Marc Knaup
05/30/2019, 3:35 PMvararg
parameter using vararg
keyword.
Reason: Make code easier to read & understand (one keyword in both locations), simplify language (no extra unary *
operator needed)
Esp. helpful for people who are new to Kotlin or have only rarely if ever use spread operators in other languages.
Example:
ByteString.of(*buffer.toByteArray())
->
ByteString.of(vararg buffer.toByteArray())
At the declaration-site vararg
denotes "variadic number of parameters".
At the call-site vararg
denotes "variadic number of arguments".Marc Knaup
05/30/2019, 3:35 PMPavlo Liapota
05/30/2019, 3:58 PMByteString.of(1, *byteArrayOf(2, 3), 4, 5, *byteArrayOf(6, 7))
And vararg
instead of *
is less readable in this case.Marc Knaup
05/30/2019, 4:02 PMvararg
would make it longer and less concise, yes.
It could still be more readable and comprehensible esp. in more complex cases where it's not that easy to spot these *
and immediately see their meaning.poohbar
06/04/2019, 4:44 PM*
worked on arrays and Lists. I am always tripped up by it.Matej Drobnič
06/05/2019, 7:08 PMMatej Drobnič
06/05/2019, 7:09 PMArrays.toString
and get garbage output)karelpeeters
06/05/2019, 7:10 PM