jnrlodge.blogg.se

Kotlin list to vararg
Kotlin list to vararg










kotlin list to vararg

The data classes, List, Map and Set have a generated shallow equals.Įnums allow you to construct ordinal data representations that map names to integers.

kotlin list to vararg

This can either perform a shallow or a deep comparison.Īrrays have a referential definition of equals, but you can also use contentEquals for a shallow structural equals and contentDeepEquals for a deep structural equals. If you want equality to be correctly interpreted for your custom classes you need to implement your own equals method. There are two basic equality operators = for equality of reference and = for structural or content equality. Kotlin doesn’t provide structs or any value alternative to classes, but it does provide a data class which has data properties and a set of methods to work with them.Įquality is a difficult thing to define in an object-oriented world.

kotlin list to vararg

The spread operator passes the array as if it was a set of individual parameters. The asList method expects a vararg of the individual elements that will be used to create the list. You can think of it as unpacking the array into separate parameters, which is why it can be regarded as a destructuring operator. It allows you to pass an array directly to the varargs as an array. What if you already have the arguments in an array? This is where the spread operator, * comes in. If you pass parameters to a vararg one by one it builds an array for you to hold them. There is one special type of destructuring designed to make it easier to use varargs.












Kotlin list to vararg