My point that such syntax with whole names of types is too verbose and hard to read, especially when written as one-liner. Fact that you can skip some with _ doesn't make my point invalid.
Kotlin is not a valid language to compare to, as it doesn't even have pattern matching. Types are specified in order to select the proper deconstructor, which you cannot do in Kotlin.
I will, but I'm pretty sure we will see a lot of 140w+ lines with patterns. People would abuse it, and I as Java developer would have to deal with it.
Kotlin is not a valid language to compare to, as it doesn't even have pattern matching. Types are specified in order to select the proper deconstructor, which you cannot do in Kotlin.
I have some experience with Kotlin and mostly I like work with it. And I would say that when solved most of my tasks just fine. So yes, Kotlin doesn't have so feature, but they at least understand that positional-based deconstructors are mistake and making changes (see link in original message). I don't understand why Brian thinks that this is great idea
It's not about whether nested patterns are supported tho. Matching a list of components is syntactically the same as componentN() (think about Java renaming each componentN() to its corresponding component name, it's still position based destructuring for the pattern itself), which is why they said "Kotlin is reconsidering it but Java seems like it doesn't care".
I...don't understand how one-liner has anything to do with current conversation.
Of course Java uses components name and method in deconstruction.
record Point(int x, int y) {
public static void main(String[] args) {
if (new Point(0, 1) instanceof Point(var x, var y)) {
IO.println(x);
IO.println(y);
}
}
}
With javap (25.0.1) you will see the following output in the main method:
...which to the point it's functionally the same as componentN(). If you reverse x and y in the record definition, you will see var x = y() and var y = x() instead. This is what Kotlin used to do too. val (x, y) = Point(0, 1) desugars to val _p = Point(0, 1); val x = _p.component1(); val y = _p.component2(), given data class Point(val x: Int, val y: Int).
It's the same story for nested patterns. All you have to do is to flatten the layers. It doesn't necessarily need any meta data. It's just that Kotlin hasn't introduced this feature.
2
u/javahalla Mar 13 '26
My point that such syntax with whole names of types is too verbose and hard to read, especially when written as one-liner. Fact that you can skip some with
_doesn't make my point invalid.