Java

Java

Made by DeepSource

Protected fields in a final class are useless JAVA-W0417

Anti-pattern
Minor
Autofix

This class is declared to be final, but declares fields to be protected. Such code is confusing, since protected fields in final classes are effectively the same as private fields.

Bad Practice

final class A {

      // This field is effectively private since A cannot be subclassed further.
      protected int abc;

}

Recommended

Since the class is final, it can not be derived from, and a protected field in a final class is essentially private. The access modifier for the field should be changed to private or public to represent the true use for the field.

final class A {

      private int abc;

}

References