Open ilya-g opened 3 years ago
Have you considered adding synthetic operator fun componentN()
functions when seeing records from Kotlin? Like you say yourself, in record declarations the order of the compoents becomes significant. This would enable destructuring on records (like on data classes).
Maybe worth adding to the Future Improvements section
That would negate the whole nominal aspect of records by introducing positional dependencies from Kotlin code. It means you could no longer add a property to the record anywhere but the end while retaining binary compatibility. This is the same problem that plagues data class
es in public API today.
Java might go that direction anyway (with deconstruction patterns, which will be generated for records). It would probably be best wait to see what that will look like before trying to make it work from Kotlin. I agree it shouldn't be a thing straight away but I thought it was worth asking what the team's opinion was.
@Cottand > Java might go that direction anyway...
It might, or it might not. We can wait and see. We can always add componentN
if Java goes ahead with positional deconstruction, but removing what you have added is much harder.
Brian Goetz indicated that deconstruction will likely be signature-based like a constructor when I asked him about it for my KotlinConf presentation last year: https://twitter.com/BrianGoetz/status/1200045322694729729.
This proposal is to introduce JVM records support in Kotlin.
Essentially, it covers two aspects: how records declared in Java should be seen in Kotlin and how to declare a record in Kotlin.
The proposal text: https://github.com/Kotlin/KEEP/blob/master/proposals/jvm-records.md