lambda表达式用法
前置条件
- 抽象类(接口,抽象类)中只有一个抽象函数
使用格式
普通版代码
package alikecheng;
@FunctionalInterface
interface Imessage1 {
public int send (int x1,int x2) ;
}
public class Ali_30 {
public static void main(String[] args) {
Imessage1 m = (x1,x2)-> {
return x1+x2;
};
System.out.println(m.send(10,20));
}
}
简化版代码(只有一行语句返回)
package alikecheng;
@FunctionalInterface
interface Imessage1 {
public int send (int x1,int x2) ;
}
public class Ali_30 {
public static void main(String[] args) {
Imessage1 m = (x1,x2)->x1+x2;
System.out.println(m.send(10,20));
}
}