Java8新特性之Lambda表达式(2)

时间:2021-05-06 18:47:23
package cn.mldn.demo;


interface Messages
{
public void print();
}
interface MyMath{
public int add(int x,int y);
}
public class TestDemo {


public static void main(String[] args) {
//单行语句
Messages message=()->System.out.println("Lambda表达式输出方式一!");
message.print();
//表达式  默认是直接返回(省略return)
MyMath math=(x,y)-> x+y;
System.out.println("加法计算结果:"+math.add(85, 85));
//多行语句
MyMath math1=(x,y)->
{
int sum=x+y;
return sum;
};
System.out.println("多行语句:"+math1.add(81, 82));
}


}