All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.S1609.html Maven / Gradle / Ivy

There is a newer version: 8.6.0.37351
Show newest version

A Single Abstract Method (SAM) interface is a Java interface containing only one method. The Java API is full of SAM interfaces, such as java.lang.Runnable, java.awt.event.ActionListener, java.util.Comparator and java.util.concurrent.Callable. SAM interfaces have a special place in Java 8 because they can be implemented using Lambda expressions or Method references.

Using @FunctionalInterface forces a compile break when an additional, non-overriding abstract method is added to a SAM, which would break the use of Lambda implementations.

Note that this rule is automatically disabled when the project's sonar.java.source is lower than 8.

Noncompliant Code Example

public interface Changeable<T> {
  public void change(T o);
}

Compliant Solution

@FunctionalInterface
public interface Changeable<T> {
  public void change(T o);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy