2020-9-15 Released JDK15
JDK15 There are altogether 14 New features , Among them, the most impressive thing for the author is that —— Sealed classes can be inherited

From the beginning, sealed classes have learned from various ways that they cannot be inherited , If you want to inherit a new version of the sealed class, you need to use permits Specifies the inherited class
meanwhile , Inherited classes need to use final,sealed perhaps non-sealed modification

A normal code idea
public class Person { } class Teacher extends Person { } // teacher class Student
extends Person { } // student class MiddleSchoolStudent extends Student { } // middle school student
class GraduateStudent extends Student { } // graduate student class Worker extends Person{ }
// worker class RailWayWorker extends Worker{ } // Railway workers
If Person add sealed You'll report a mistake
public sealed class Person { } class Teacher extends Person { } // teacher class
Student extends Person { } // student class MiddleSchoolStudent extends Student { }
// middle school student class GraduateStudent extends Student { } // graduate student class Worker extends
Person{ } // worker class RailWayWorker extends Worker{ } // Railway workers
In this case, if you want the sealed class to be inherited, you need to use the permits Specifies the inherited class , If the inherited class has no final,sealed perhaps non-sealed It's also a mistake
public sealed class Person permits Teacher,Student,Worker{ } final class
Teacher extends Person { } // teacher sealed class Student extends Person permits
MiddleSchoolStudent,GraduateStudent{ } // student final class MiddleSchoolStudent
extends Student { } // middle school student final class GraduateStudent extends Student { } // graduate student
non-sealed class Worker extends Person{ } // worker class RailWayWorker extends
Worker{ } // Railway workers
You can see , Classes that inherit sealed classes ,
If it's a sealed class, you need to inherit , Also need to be specified
If it's an unsealed class , It can be used normally , Normally inherited .

alas , Sealed classes can be inherited , Subvert my three views since I learned code

Technology