Path: blob/master/src/java.base/share/classes/java/lang/FunctionalInterface.java
41152 views
/*1* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.lang;2627import java.lang.annotation.*;2829/**30* An informative annotation type used to indicate that an interface31* type declaration is intended to be a <i>functional interface</i> as32* defined by the Java Language Specification.33*34* Conceptually, a functional interface has exactly one abstract35* method. Since {@linkplain java.lang.reflect.Method#isDefault()36* default methods} have an implementation, they are not abstract. If37* an interface declares an abstract method overriding one of the38* public methods of {@code java.lang.Object}, that also does39* <em>not</em> count toward the interface's abstract method count40* since any implementation of the interface will have an41* implementation from {@code java.lang.Object} or elsewhere.42*43* <p>Note that instances of functional interfaces can be created with44* lambda expressions, method references, or constructor references.45*46* <p>If a type is annotated with this annotation type, compilers are47* required to generate an error message unless:48*49* <ul>50* <li> The type is an interface type and not an annotation type, enum, or class.51* <li> The annotated type satisfies the requirements of a functional interface.52* </ul>53*54* <p>However, the compiler will treat any interface meeting the55* definition of a functional interface as a functional interface56* regardless of whether or not a {@code FunctionalInterface}57* annotation is present on the interface declaration.58*59* @jls 4.3.2 The Class Object60* @jls 9.8 Functional Interfaces61* @jls 9.4.3 Interface Method Body62* @jls 9.6.4.9 @FunctionalInterface63* @since 1.864*/65@Documented66@Retention(RetentionPolicy.RUNTIME)67@Target(ElementType.TYPE)68public @interface FunctionalInterface {}697071