Skip to content

Latest commit

 

History

History
16 lines (14 loc) · 752 Bytes

AvoidProtectedMethodInFinalClassNotExtending.md

File metadata and controls

16 lines (14 loc) · 752 Bytes

AvoidProtectedMethodInFinalClassNotExtending

Category: pmd
Rule Key: pmd:AvoidProtectedMethodInFinalClassNotExtending

⚠️ This rule is deprecated in favour of S2156.


Do not use protected methods in most final classes since they cannot be subclassed. This should only be allowed in final classes that extend other classes with protected methods (whose visibility cannot be reduced). Clarify your intent by using private or package access modifiers instead. Example:

public final class Foo {
  private int bar() {}
  protected int baz() {} // Foo cannot be subclassed, and doesn't extend anything, so is baz() really private or package visible? 
}