Java sealed classes and exhaustive pattern matching

neilmadden.blog

103 points by hnisjafx40 6 hours ago


shepherdjerred - an hour ago

I love how far Java has come. I still prefer TypeScript since I do a lot of frontend work and prefer to use the same language across the stack.

With the said, you can do exhaustive pattern matching in TypeScript! https://github.com/gvergnaud/ts-pattern

armchairhacker - 5 hours ago

Java also has recursive patterns and (maybe still in preview) literal patterns: `switch (x) { case A(B(true, var c)) -> f(c); }`

timshel2 - 4 hours ago

Scala punching the air rn

curatedmcp - 9 minutes ago

[dead]

Larrikin - 5 hours 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