Java sealed classes and exhaustive pattern matching
24 points by hnisjafx40 2 hours ago | 5 comments

timshel2 2 minutes ago
Scala punching the air rn
reply
armchairhacker 57 minutes ago
Java also has recursive patterns and (maybe still in preview) literal patterns: `switch (x) { case A(B(true, var c)) -> f(c); }`
reply
Larrikin 56 minutes ago
Java continues to try and catch up to Kotlin https://kotlinlang.org/docs/sealed-classes.html

I didn't mind Java when the comparisons were to C++, Ruby, and Python. I can not find a reason to go back after Scala (which seemed to fail due to being indiscriminate) and especially Kotlin

reply
sideeffffect 28 minutes ago
> Java continues to try and catch up to Kotlin

Does it, really? Java has had pattern matching since 21 (2023). Kotlin still, to this day, the year of our Lord 2026, doesn't...

reply
troupo 6 minutes ago
Of all languages the only one it's trying to catch up to (and in places outran) is C#

With many others it doesn't compete because it would need a from-scratch rewrite of the runtime (Erlang/Elixir), or a from-scratch redesign of the type system (Rust, perhaps Swift).

reply