lambda函数式编程

Posted on 2018-09-01 14:43  lhj1006400320  阅读(94)  评论(0)    收藏  举报

一、接口注解(@FunctionalInterface)

@FunctionalInterface
interface Interface1 {
    public void print();
}

public class LambdaTest {
    public static void main(String[] args) {
//        Interface1 i = new Interface1() {
//            @Override
//            public void print() {
//                System.out.println("QAQ");
//            }
//        };
        Interface1 i = () -> System.out.println(" I am lambda Demo");

        i.print();
    }
}

二、引用

  • 引用静态方法:类名称 :: static方法名称
  • 引用某个对象方法:实例化对象 :: 普通方法名称
  • 引用某个特定类的方法:类名称 :: 普通方法名称
  • 引用构造方法:类名称 :: new 。

 

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3