Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-2333

Redundant modifiers should not be used

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      "xxx" is redundant in this context.
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Covered Languages:
      C#, Java
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2min
    • Analysis Scope:
      Main Sources, Test Sources
    • Checkstyle:
      RedundantModifier
    • ReSharper:
      PartialTypeWithSinglePart, SealedMemberInSealedClass, RedundantUnsafeContext

      Description

      The methods declared in an interface are public and abstract by default. Any variables are automatically public static final. Finally, class and interface are automatically public static. There is no need to explicitly declare them so.

      Since annotations are implicitly interfaces, the same holds true for them as well.

      Similarly, the final modifier is redundant on any method of a final class, private is redundant on the constructor of an Enum, and static is redundant for interface nested into a class or enum.

      Noncompliant Code Example

      public interface Vehicle {
      
        public void go(int speed, Direction direction);  // Noncompliant
      

      Compliant Solution

      public interface Vehicle {
      
        void go(int speed, Direction direction);
      

        Attachments

          Issue Links

          1.
          C# RSPEC-3248 Language-Specification Active Unassigned

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ann.campbell.2 Ann Campbell
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: