24 lines
763 B
Java
24 lines
763 B
Java
package com.inmind.functional_interface02;
|
|
//函数式接口:有且仅有一个必须重写的抽象方法的接口
|
|
public class Demo03 {
|
|
public static void main(String[] args) {
|
|
int i = 10;
|
|
int j = 20;
|
|
//调用使用函数式接口的方法
|
|
/*int result = getResult(new MyInterface() {
|
|
@Override
|
|
public int getSum(int a, int b) {
|
|
return a+b;
|
|
}
|
|
}, i, j);*/
|
|
|
|
// int result = getResult((int a, int b)->{return a+b;}, i, j);
|
|
int result = getResult(( a, b)-> a+b, i, j);
|
|
System.out.println(result);
|
|
}
|
|
public static int getResult(MyInterface myInterface,int a,int b) {
|
|
int sum = myInterface.getSum(a, b);
|
|
return sum;
|
|
}
|
|
}
|