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."],[[["\u003cp\u003e\u003ccode\u003e@FunctionalInterface\u003c/code\u003e annotation indicates that an interface is designed to be a functional interface, meaning it has a single abstract method.\u003c/p\u003e\n"],["\u003cp\u003eDefault methods and methods overriding \u003ccode\u003ejava.lang.Object\u003c/code\u003e's public methods don't count towards the abstract method count for a functional interface.\u003c/p\u003e\n"],["\u003cp\u003eCompilers enforce the functional interface requirements when \u003ccode\u003e@FunctionalInterface\u003c/code\u003e is present, generating an error if the annotated type doesn't meet the criteria.\u003c/p\u003e\n"],["\u003cp\u003eFunctional interfaces can be instantiated using lambda expressions, method references, or constructor references.\u003c/p\u003e\n"],["\u003cp\u003eEven without the \u003ccode\u003e@FunctionalInterface\u003c/code\u003e annotation, the compiler recognizes and treats any interface meeting the functional interface definition as such.\u003c/p\u003e\n"]]],["The `@FunctionalInterface` annotation indicates an interface intended as a functional interface, having exactly one abstract method. Default methods and overridden `java.lang.Object` methods are not counted. Instances can be created via lambdas, method references, or constructor references. Compilers must flag errors if an annotated type is not an interface or doesn't meet the functional interface definition. Any interface meeting these criteria is a functional interface, regardless of the annotation's presence. The annotation extends the Annotation Interface and inherits method like annotationType(), equals(), hashCode(), and toString().\n"],null,["# FunctionalInterface\n\npublic abstract @interface **FunctionalInterface** implements [Annotation](../../../reference/java/lang/annotation/Annotation.html) \nAn informative annotation type used to indicate that an interface\ntype declaration is intended to be a *functional interface* as\ndefined by the Java Language Specification.\n\nConceptually, a functional interface has exactly one abstract\nmethod. Since {@linkplain java.lang.reflect.Method#isDefault()\ndefault methods} have an implementation, they are not abstract. If\nan interface declares an abstract method overriding one of the\npublic methods of `java.lang.Object`, that also does\n*not* count toward the interface's abstract method count\nsince any implementation of the interface will have an\nimplementation from `java.lang.Object` or elsewhere.\n\nNote that instances of functional interfaces can be created with\nlambda expressions, method references, or constructor references.\n\nIf a type is annotated with this annotation type, compilers are\nrequired to generate an error message unless:\n\n- The type is an interface type and not an annotation type, enum, or class.\n- The annotated type satisfies the requirements of a functional interface.\n\nHowever, the compiler will treat any interface meeting the\ndefinition of a functional interface as a functional interface\nregardless of whether or not a `FunctionalInterface`\nannotation is present on the interface declaration. \n\n### Inherited Method Summary\n\nFrom interface [java.lang.annotation.Annotation](../../../reference/java/lang/annotation/Annotation.html) \n\n|----------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Class](../../../reference/java/lang/Class.html)\\\u003c? extends [Annotation](../../../reference/java/lang/annotation/Annotation.html)\\\u003e | [annotationType](../../../reference/java/lang/annotation/Annotation.html#annotationType())() Returns the annotation type of this annotation. |\n| abstract boolean | [equals](../../../reference/java/lang/annotation/Annotation.html#equals(java.lang.Object))([Object](../../../reference/java/lang/Object.html) obj) Returns true if the specified object represents an annotation that is logically equivalent to this one. |\n| abstract int | [hashCode](../../../reference/java/lang/annotation/Annotation.html#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()](../../../reference/java/lang/String.html#hashCode())) XOR the hash code of the member-value, as defined below: The hash code of a member-value depends on its type: - The hash code of a primitive value *v* is equal to *WrapperType* .valueOf(*v*).hashCode(), where *WrapperType* is the wrapper type corresponding to the primitive type of *v* ([Byte](../../../reference/java/lang/Byte.html), [Character](../../../reference/java/lang/Character.html), [Double](../../../reference/java/lang/Double.html), [Float](../../../reference/java/lang/Float.html), [Integer](../../../reference/java/lang/Integer.html), [Long](../../../reference/java/lang/Long.html), [Short](../../../reference/java/lang/Short.html), or [Boolean](../../../reference/java/lang/Boolean.html)). |\n| abstract [String](../../../reference/java/lang/String.html) | [toString](../../../reference/java/lang/annotation/Annotation.html#toString())() Returns a string representation of this annotation. |"]]