filmov
tv
Java 17 Sealed Classes JEP: 409
Показать описание
Java 17 Sealed Classes JEP: 409
- Sealed classes and interfaces restrict which other classes or interfaces may extend or implement them
-The sealed feature introduces a couple of new modifiers and clauses in Java: sealed, non-sealed, permits
Goals
- Allow the author of a class or interface to control which code is responsible for implementing it.
- Provide a more declarative way than access modifiers to restrict the use of a superclass.
- Support future directions in pattern matching by providing a foundation for the exhaustive analysis of patterns.
A sealed class imposes three constraints on its permitted subclasses:
- The sealed class and its permitted subclasses must belong to the same module, and, if declared in an unnamed module, to the same package.
- Every permitted subclass must directly extend the sealed class.
- Every permitted subclass must define a modifier: final, sealed, or non-sealed.
====================================================
====================================================
- Sealed classes and interfaces restrict which other classes or interfaces may extend or implement them
-The sealed feature introduces a couple of new modifiers and clauses in Java: sealed, non-sealed, permits
Goals
- Allow the author of a class or interface to control which code is responsible for implementing it.
- Provide a more declarative way than access modifiers to restrict the use of a superclass.
- Support future directions in pattern matching by providing a foundation for the exhaustive analysis of patterns.
A sealed class imposes three constraints on its permitted subclasses:
- The sealed class and its permitted subclasses must belong to the same module, and, if declared in an unnamed module, to the same package.
- Every permitted subclass must directly extend the sealed class.
- Every permitted subclass must define a modifier: final, sealed, or non-sealed.
====================================================
====================================================