问题 1
What is lambda expression?
Lambda expression is anonymous function which have set of parameters and a lambda (->) and a function body. You can call it function without name.
Structure of Lambda Expressions:
(Argument List) ->{expression;} or
(Argument List) ->{statements;}
For instance, the Runnable interface is a functional interface, so instead of:
Thread thread = new Thread(new Runnable() { public void run() { System.out.println("Hello World!"); }});Using Lambda you can simply do the following:
Thread thread = new Thread(() -> System.out.println("Hello World!"));
Functional interfaces are usually annotated with the @FunctionalInterface annotation - which is informative and does not affect the semantics.
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
这有帮助吗?
添加评论
查看评论