Redundant modifiers should not be used

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);

Message

"xxx" is redundant in this context.

Highlighting

None

List of parameters

None
0% Done
Loading...

Activity

Show:
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Labels

Default Severity

Minor

Covered Languages

C#
Java

Remediation Function

Constant/Issue

Constant Cost

Analysis Scope

Main Sources
Test Sources

Sentry

Created January 6, 2015 at 11:44 AM
Updated March 22, 2021 at 4:47 PM