Java - Algebraic data types
Java is an object-oriented language, and doesn't support algebraic data types directly but in the future releases openjdk is planning add algebraic data types features as a part of JEP 360.
Sealed types, a mechanism for declaring all possible subclasses of a class. Together with the record and pattern matching features this is used to implement algebraic data types.
A sealed type is one for which subtyping is restricted according to guidance specified with the type's declaration.
Sealing serves two distinct purposes. The first is that it restricts which classes may be a subclass of a sealed class. The second is that it potentially enables exhaustiveness analysis at the use site, such as when switching over type patterns for an instance of a sealed type.
A class is sealed by applying the sealed modifier to a class or interface, with an optional permits clause:
sealed interface Node
permits A, B, C { ... }
n computer programming, especially functional programming and type theory, an algebraic data type is a kind of composite type, i.e., a type formed by combining other types.
JEP 360: Sealed Types
Sealed types, a mechanism for declaring all possible subclasses of a class. Together with the record and pattern matching features this is used to implement algebraic data types.
A sealed type is one for which subtyping is restricted according to guidance specified with the type's declaration.
Sealing serves two distinct purposes. The first is that it restricts which classes may be a subclass of a sealed class. The second is that it potentially enables exhaustiveness analysis at the use site, such as when switching over type patterns for an instance of a sealed type.
A class is sealed by applying the sealed modifier to a class or interface, with an optional permits clause:
sealed interface Node
permits A, B, C { ... }
What is Algebraic data type?
n computer programming, especially functional programming and type theory, an algebraic data type is a kind of composite type, i.e., a type formed by combining other types.
Comments
Post a Comment