← Today's brief

Developers · Updated 18 Oct, 08:17 pm IST

Java 17 adds sealed classes to enable exhaustive pattern matching

Image: Hacker News (100+ points)

Why it matters for readers: It shows how Java is adopting ideas from functional languages to make pattern matching more precise.

  • Sealed classes let an interface or base class explicitly list its permitted subtypes.1
  • Using sealed classes with switch expressions enables compiler exhaustiveness checking so a default clause is not required if all cases are handled.1
  • The article demonstrates sealed interfaces combined with record types and a switch expression example that returns values for each case.1
  • The feature is compared to algebraic datatype declarations in functional languages like Haskell and ML.1

Get a brief like this every morning

Uzha reads hundreds of sources and gives you the stories that matter for your work, with every source linked. Free.

Get started