java 中的lambda 表达式使用1
1、lambda表达式在java中后续可能会取代匿名内部类
2、java中的函数接口(FunctionalInterface注解)
注:函数接口中只能有一个抽象方法,如果有多个方法则无法使用lambda表达式
lamda表达式替代匿名内部类方式如下
.java
@FunctionalInterface
interface ExecuteAble{
void say(String name,String msg);
}
public class RobotT{
public void say(ExecuteAble exe){
exe.say("Robot Lucy "," is laughing hahahaha......");
}
}
public class TestLambda{
public static void main (String[] args){
Robot t1 _new Robot();
t1.say(
(name,msg) -> {
system.out.println(name + msg);
} );
Robot t2 _new Robot();
//change the contents of saying
//annomous inner class
t2.say(new ExecuteAble(){
public void say(String name,String msg){
system.out.println(name + msg);
}
})
}
}