Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 除了使用Lambda表达式的不同实现之外,函数接口的用例是什么?_Java_Functional Interface - Fatal编程技术网

Java 除了使用Lambda表达式的不同实现之外,函数接口的用例是什么?

Java 除了使用Lambda表达式的不同实现之外,函数接口的用例是什么?,java,functional-interface,Java,Functional Interface,我想知道除了使用lambda表达式的不同实现之外,函数接口的用例是什么 以下是功能接口的基本示例: /*Basic example for Functional interface with Lambda expression*/ public class Lambda_test { /* * Functional Interface annotation will not allow to declare more than one * abstract met

我想知道除了使用lambda表达式的不同实现之外,函数接口的用例是什么

以下是功能接口的基本示例:

/*Basic example for Functional interface with Lambda expression*/

public class Lambda_test {

    /*
     * Functional Interface annotation will not allow to declare more than one
     * abstract method which is obvious for the concept
     */

    @FunctionalInterface
    interface NameTest {

        // One abstract method
        abstract String MyName(String name);


    }

    public static void main(String[] args) {

        NameTest nametest = (name) -> "Ashwin " + name + "!";

        System.out.println("My name is " + nametest.MyName("Savaj"));

    }

}

根据java规范

函数接口是只有一个抽象方法的接口 除了对象的方法外,因此表示单个对象 功能合同

因为默认方法有一个实现,所以它们不是抽象的

如果是@functionInterface: 编译器将生成错误消息,除非:

该类型是接口类型,而不是批注类型、枚举或 班 带注释的类型满足函数的要求 界面