
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
58 lines
1.5 KiB
Plaintext
58 lines
1.5 KiB
Plaintext
== Why is this an issue?
|
|
|
|
``++sealed++`` classes were introduced in Java 17. This feature is very useful if there is a need to define a strict hierarchy and restrict the possibility of extending classes. In order to mention all the allowed subclasses, there is a keyword ``++permits++``, which should be followed by subclasses' names.
|
|
|
|
|
|
This notation is quite useful if subclasses of a given ``++sealed++`` class can be found in different files, packages, or even modules. In case when all subclasses are declared in the same file there is no need to mention the explicitly and ``++permits++`` part of a declaration can be omitted.
|
|
|
|
|
|
This rule reports an issue if all subclasses of a ``++sealed++`` class are declared in the same file as their superclass.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
sealed class A permits B, C, D, E {} // Noncompliant
|
|
final class B extends A {}
|
|
final class C extends A {}
|
|
final class D extends A {}
|
|
final class E extends A {}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
sealed class A {} // Compliant
|
|
final class B extends A {}
|
|
final class C extends A {}
|
|
final class D extends A {}
|
|
final class E extends A {}
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* https://docs.oracle.com/javase/specs/jls/se17/html/jls-8.html#jls-8.1.1.2[Sealed Classes specification]
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Remove this redundant permitted list.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
permits keyword with secondary on types
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|