Skip to content

Alternative design for closed keyword and union types #9509

Discussion options

You must be logged in to vote

The nominal type union syntax is already pretty terse for existing case types:

public union MyAnimals (Cat, Dog);

That is different from closed which is intended to declare a closed type hierarchy, or one with a known set of direct descendants. That syntax is borrowing from Java, which uses the sealed keyword:

public sealed interface Shape { }
public record Circle(float radius) implements Shape { }
public record Square(float side) implements Shape { }
public record Rectangle(float length, float height) implements Shape { }

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by lt-gerjan
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants