Sealed interfaces in Java

 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

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...