0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

java中的lambda表达式1

Last updated at Posted at 2018-02-21

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);
             }
        })
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?