Latest Java release 15 offers new functionality - sealed
modifier. I went through the JEP and it says:
Sealed classes and interfaces restrict which other classes or interfaces may extend or implement them.
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 underpinning the exhaustive analysis of patterns.
First and second are pretty straightforward, but the third one could hardly be followed. Could somebody explain, please, how sealed
will help with pattern matching
?