Sealed classes and interfaces restrict/limit, which other classes or interfaces may extend or implement them. It enhance the Java programming language with sealed classes and interfaces.
A class can be sealed by using the sealed modifier - permits to its declaration. After which any extends and implements clauses, the permits clause specifies the classes that are permitted/allowed to extend the sealed class.
Example: Below example shows how Animal class specifies three permitted subclasses:
package com.techgeeknext.example.species;
public sealed class Animal
permits Dog, Monkey, Leopard {...}
#JavaBeam #SealedClassesInJava15 #java #Java15
Смотрите видео Java 15 new features | sealed classes in java 15 | Java Beam онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Java Beam 20 Сентябрь 2020, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 501 раз и оно понравилось 9 людям.