Sometimes we write something for the book, only to realize it shouldn’t be in the book. This post is an example. Do you think this legal?
1 2 3 4 5 6 | public sealed interface MySealedClass permits MyRecord, MyEnum { } record MyRecord() implements MySealedClass {} enum MyEnum implements MySealedClass { VALUE } |
It is! A sealed interface can be implemented by any Java type. Which means records and enums are included.