FunctionalInterface
Stay organized with collections
Save and categorize content based on your preferences.
An informative annotation type used to indicate that an interface
type declaration is intended to be a functional interface as
defined by the Java Language Specification.
Conceptually, a functional interface has exactly one abstract
method. Since {@linkplain java.lang.reflect.Method#isDefault()
default methods} have an implementation, they are not abstract. If
an interface declares an abstract method overriding one of the
public methods of java.lang.Object
, that also does
not count toward the interface's abstract method count
since any implementation of the interface will have an
implementation from java.lang.Object
or elsewhere.
Note that instances of functional interfaces can be created with
lambda expressions, method references, or constructor references.
If a type is annotated with this annotation type, compilers are
required to generate an error message unless:
- The type is an interface type and not an annotation type, enum, or class.
- The annotated type satisfies the requirements of a functional interface.
However, the compiler will treat any interface meeting the
definition of a functional interface as a functional interface
regardless of whether or not a FunctionalInterface
annotation is present on the interface declaration.
Inherited Method Summary
From interface
java.lang.annotation.Annotation
abstract
Class<? extends Annotation>
|
|
abstract
boolean
|
equals( Object obj)
Returns true if the specified object represents an annotation
that is logically equivalent to this one.
|
abstract
int
|
hashCode()
Returns the hash code of this annotation, as defined below:
The hash code of an annotation is the sum of the hash codes
of its members (including those with default values), as defined
below:
The hash code of an annotation member is (127 times the hash code
of the member-name as computed by String.hashCode() ) XOR
the hash code of the member-value, as defined below:
The hash code of a member-value depends on its type:
|
abstract
String
|
toString()
Returns a string representation of this annotation.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["`@FunctionalInterface` annotation indicates that an interface is designed to be a functional interface, meaning it has a single abstract method."],["Default methods and methods overriding `java.lang.Object`'s public methods don't count towards the abstract method count for a functional interface."],["Compilers enforce the functional interface requirements when `@FunctionalInterface` is present, generating an error if the annotated type doesn't meet the criteria."],["Functional interfaces can be instantiated using lambda expressions, method references, or constructor references."],["Even without the `@FunctionalInterface` annotation, the compiler recognizes and treats any interface meeting the functional interface definition as such."]]],[]]