https://kotlinlang.org logo
#announcements
Title
# announcements
l

louiscad

06/04/2019, 9:00 PM
@thana I submitted a feature request for allowing to explicitly request use of
contentEquals
a while ago: https://youtrack.jetbrains.com/issue/KT-26499 You can add your vote.
e

elizarov

06/04/2019, 9:06 PM
I always wanted to ask what’s the use-case of storing arrays in data classes? Where does it come up?
b

basher

06/04/2019, 10:13 PM
I can't recall if `inline class`es can do this, but this kind of thing is useful in other languages when you want type-level validation:
data class NonEmptyList<T>(val values: List<T>)
then you throw in
init
if the list is empty. That's the use case that comes to mind for me anyway
p

Pavlo Liapota

06/05/2019, 5:16 AM
@basher but you are storing
List
, not
Array
🙂
t

thana

06/05/2019, 5:56 AM
@elizarov in my case i need to satisfy a javascript interface which requires an array here and not a list
👍 1
e

elizarov

06/05/2019, 6:03 AM
Ah, I see. Inline classes would help here when they are really supported by JS backend.
b

basher

06/05/2019, 2:56 PM
@Pavlo Liapota fair point! Same idea though?
p

Pavlo Liapota

06/05/2019, 3:07 PM
The issue is with arrays only.
equals()
of a
List
compares elements and
toString()
shows elements, but it does not like that for arrays.
Copy code
arrayOf(1) == arrayOf(1) // false
listOf(1) == listOf(1) // true
👍 1
l

louiscad

06/05/2019, 3:14 PM
@elizarov Use case is for primitive arrays and unsigned number arrays, where using
List
means performance hit due to autoboxing and you don't need variable size or read-only defense.
e

elizarov

06/05/2019, 3:21 PM
Thanks. That makes sense.
3 Views