# Remove Modifiers in Interface Properties

# Description

By default, the attributes declared in Java interfaces are public. This rule, removes the public modifiers from method declarations and public static final modifiers from field declarations in interfaces.

Note, from Java 9 it is possible to have private methods (opens new window) in interfaces, too.

# Benefits

Removes the clutter and unifies the attributes of Java interfaces.

# Tags

# Code Changes

Pre

public interface InterfaceWithProperties {
	
	public String FIELD_WITH_PUBLIC_MODIFIER = "";
	
	public static String FIELD_WITH_PUBLIC_STATIC_MODIFIER = "";
	
	public static final String FIELD_WITH_PUBLIC_STATIC_FINAL_MODIFIER = "";
	
	void method();
	
	public void publicMethod();
	
	public static void publicStaticMethod() {
		
	}
	
	public default void publicDefaultMethod() {
		
	}
}

Post

public interface InterfaceWithProperties {
	
	String FIELD_WITH_PUBLIC_MODIFIER = "";
	
	String FIELD_WITH_PUBLIC_STATIC_MODIFIER = "";
	
	String FIELD_WITH_PUBLIC_STATIC_FINAL_MODIFIER = "";
	
	void method();
	
	void publicMethod();
	
	static void publicStaticMethod() {
		
	}
	
	default void publicDefaultMethod() {
		
	}
}

Use a Java Refactoring Tool

No license required

You can review this refactoring on your code without a license by installing jSparrow to your Eclipse IDE. Install the plug-in from Eclipse IDE: Eclipse Marketplace.

System-wide Refactoring

Do you want to automate this refactoring (and many more) to your system-wide code? The automatic application of this system-wide refactoring can be unlocked by acquiring your jSparrow license.

a drawn cute bird pointing at a graph that shows positive results

# Properties

Property Value
Rule ID RemoveModifiersInInterfaceProperties
First seen in jSparrow version 3.3.0
Minimum Java version 1.1
Remediation cost 1 min
Links