> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Java FunctionalInterface Annotation

The `@FunctionalInterface` annotation is an informative, type-level annotation introduced in Java 8 that indicates an interface declaration is intended to be a functional interface. It instructs the Java compiler to enforce the Single Abstract Method (SAM) rule, triggering a compilation error if the annotated interface contains more or fewer than exactly one abstract method.

```java theme={"dark"}
@FunctionalInterface
public interface SimpleFunctionalInterface {
    void execute();
}
```

## Compiler Rules and Mechanics

When the compiler encounters the `@FunctionalInterface` annotation, it evaluates the interface against a strict set of structural rules. To pass compilation, the interface must adhere to the following:

1. **Single Abstract Method (SAM):** The interface must declare exactly one un-implemented (abstract) method.
2. **Default Methods:** The interface may contain any number of `default` methods. Because default methods provide an implementation, they do not count toward the SAM limit.
3. **Static Methods:** The interface may contain any number of `static` methods. Like default methods, these are implemented and do not violate the SAM rule.
4. **Object Class Methods:** If an interface declares an abstract method overriding one of the public methods of `java.lang.Object` (such as `equals`, `hashCode`, or `toString`), that method does *not* count toward the single abstract method limit. This is because any implementation of the interface will implicitly inherit implementations for these methods from `Object`.

```java theme={"dark"}
@FunctionalInterface
public interface ComplexFunctionalInterface {
    // 1. The Single Abstract Method (SAM)
    void process(String data);

    // 2. Default methods are permitted
    default void log(String msg) {
        System.out.println(msg);
    }

    // 3. Static methods are permitted
    static boolean isValid(String data) {
        return data != null && !data.isEmpty();
    }

    // 4. Overriding public Object methods does not violate the SAM rule
    @Override
    boolean equals(Object obj);
}
```

## Technical Characteristics

* **Optionality:** The annotation is not strictly mandatory. The Java compiler automatically treats any interface meeting the SAM criteria as a functional interface, allowing it to be the target type for lambda expressions and method references. However, applying the annotation acts as a compiler assertion, preventing future modifications from accidentally breaking the SAM contract by adding additional abstract methods.
* **Target Restriction:** The annotation is meta-annotated with `@Target(ElementType.TYPE)`. It can only be applied to interface declarations. Applying it to a class, enum, or annotation type results in a compilation error.
* **Retention:** It is meta-annotated with `@Retention(RetentionPolicy.RUNTIME)`. While its primary utility is compile-time validation, the annotation is preserved in the bytecode and remains accessible at runtime via reflection.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Java Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
