3 ms·
I wonder why, unlike a Java record, in Kotlin a data class annotated with @Record can not be local. Being able to use local records is a useful feature in part
by _old_dude_ 5y ago
I wonder why, unlike a Java record, in Kotlin a data class annotated with @Record can not be local.
Being able to use local records is a useful feature in particular in unit tests.
@Test
void testPoints() {
record Point(int x, int y) {}
...
}
- tadfisher 5y agoI don't see the point; you're not testing code that depends on Point, as it's local, so `x to y` (i.e. `Pair(x, y)`) would work just as well. If there's a particular language feature records enable that Kotlin doesn't with ordinary data classes in this case, I'd love to see it.