Hacker News new | ask | show | jobs
by fulafel 1704 days ago
Question from a non Java programmer, where can I read more about algebraic data types in Java? The article doesn't mention the term.
1 comments

They are not used that much yet, and the whole deal (with destructuring pattern matching) is not yet ready, but it is basically just records as (nominal) product types and sealed classes as sum types.

What is already possible with switch expressions is branching based on type, in a much more ML-like style like case Point p -> … which doesn’t require instanceof checks and castings, but it will soon become Point(x, y), where the x, y will automatically get the values of the corresponding fields.