In the following example why do I explicitly need to specify a class Square as non-sealed?
Isn't public class Square extends Shape {...} more intuitive?
package com.example.geometry;
public abstract sealed class Shape permits Circle, Rectangle, Square {...}
public final class Circle extends Shape {...}
public sealed class Rectangle extends Shape permits TransparentRectangle, FilledRectangle {...} public final class TransparentRectangle extends Rectangle {...} public final class FilledRectangle extends Rectangle {...}
public non-sealed class Square extends Shape {...}
I could not see any explanation at JEP 360
You said you “could not see any explanation at JEP 360” but the linked document says explicitly:
The last point indicates the intended mindset: a sealing is initiated by a class declared
sealedbut is not just about the direct subclasses but the entire type hierarchy. Therefore, the permitted subclasses must declare, how to continue the sealing, either by beingfinalorsealedor by explicitly declaring a re-opened branch of the class tree.Opening (resp. accidentally breaking) a sealing by just not declaring an appropriate modifier, which could be an oversight, is not an option.
The available options are also listed directly under the cited part:
The JEP doesn’t mention it but the specification allows implicit declarations, so you don’t need to specify
sealedorfinalforenumorrecordtypes implementing a sealed interface.