美文网首页
lambda系列——几种形式

lambda系列——几种形式

作者: hello高world | 来源:发表于2017-01-04 09:42 被阅读0次

【lambda系列——5种形式】

     from java8函数式编程
package org.java8.lambda;

import java.awt.event.ActionListener;
import java.util.function.BinaryOperator;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class First {

    public static void main(String[] args) {
        Runnable noArguments = () -> System.out.println("Hello World");
        //如果只有一个参数,可以把括号去掉
        ActionListener oneArgument = event -> System.out.println("button clicked");
        
        Runnable multiStatement = () -> {
            System.out.print("Hello");
            System.out.println(" World");
        };
        
        BinaryOperator<Long> add = (x, y) -> x + y;
        BinaryOperator<Long> addExplicit = (Long x, Long y) -> x + y;
        
        log.info("add: {} + {} = {}", 1L, 2L, add.apply(1L, 2L));
        log.info("addExplicit: {} + {} = {}", 3L, 4L, addExplicit.apply(3L, 4L));
        
    }
}

相关文章

网友评论

      本文标题:lambda系列——几种形式

      本文链接:https://www.haomeiwen.com/subject/yplovttx.html