Java sealed classes and exhaustive pattern matching

(neilmadden.blog)

22 points | by hnisjafx40 1 hour ago

2 comments

  • armchairhacker 50 minutes ago
    Java also has recursive patterns and (maybe still in preview) literal patterns: `switch (x) { case A(B(true, var c)) -> f(c); }`
  • Larrikin 49 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

    • sideeffffect 20 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...