Lambda表达式练习(抽象带参带返回值)

package com.czie.iot1913.Java8.Lambda.LambdaTest01.Practice02;

/**
* FileName: AddableDemo
* Author: lps
* Date: 2022/4/3 16:25
* Sign:刘品水 Q:1944900433
*/
public class AddableDemo {
public static void main(String[] args) {
// useAddable(new Addable() {
// @Override
// public int add(int x, int y) {
// System.out.println(x+y);
// return x+y;
// }
// });
//
// //lambda表达式
// useAddable(((x, y) -> {
// System.out.println(x+y);
// return x+y;
// }));
useAddable(new Addable() {
@Override
public int add(int x, int y) {
return x+y;
}
});

//lambda
useAddable(((x, y) -> x+y));

}
public static void useAddable(Addable a){
int sum=a.add(10,20);
System.out.println(sum);
}
}

package com.czie.iot1913.Java8.Lambda.LambdaTest01.Practice02;

/**
* FileName: Addable
* Author: lps
* Date: 2022/4/3 16:25
* Sign:刘品水 Q:1944900433
*/
public interface Addable {
int add(int x,int y);
}

 

posted @ 2022-04-03 16:49  刘品水  阅读(36)  评论(0编辑  收藏  举报