Sealed Enums
Java 17 also introduced the ability to declare sealed enums. Sealed enums allow developers to restrict the number of enum constants to a fixed set of constants.
Example:
public sealed enum Color permits Red, Green, Blue {}
public enum Red implements Color { RED }
public enum Green implements Color { GREEN }
public enum Blue implements Color { BLUE }
No comments:
Post a Comment