Sealed interfaces
Java 17 introduced the ability to declare sealed interfaces. Sealed interfaces allow developers to restrict the number of implementations of an interface to a fixed set of classes.
Example:
public sealed interface Shape permits Circle, Rectangle, Triangle {}
public final class Circle implements Shape {}
public final class Rectangle implements Shape {}
public final class Triangle implements Shape {}
No comments:
Post a Comment