zoukankan      html  css  js  c++  java
  • 方法引入

    package com.mayikt.service;
    
    /**
     * @ClassName MessageInterface
     * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com
     * @Version V1.0
     **/
    @FunctionalInterface
    public interface MessageInterface {
        String get(Integer a, Integer b);
    }

    package com.mayikt.method;
    
    import com.mayikt.service.MessageInterface;
    
    /**
     * @ClassName Test012
     * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com
     * @Version V1.0
     **/
    public class Test012 {
        public static void main(String[] args) {
            // 1.最原生匿名内部类调用方式
    //        MessageInterface messageInterface = new MessageInterface() {
    //            @Override
    //            public void get(Integer a) {
    //                System.out.println("geta:" + a);
    //            }
    //        };
    //        messageInterface.get(1);
    
            // 在Lambda表达式中方法体直接引入方法
    //        MessageInterface messageInterface2 = (a) -> Test012.staticGet(a);
    //        // 方法引入 --实际上就是我们 Lambda表达式中方法体直接引入方法---
    //        messageInterface2.get(2);
    //        // 方法引入写法
    //        MessageInterface messageInterface3 = Test012::staticGet;
    //        messageInterface3.get(10,20);
            /**
             *Test012::staticGet为何能够等于
             * (a) -> Test012.staticGet(a);
             */
        }
    
        public static String  staticGet(Integer a, Integer b) {
            System.out.println("staticGet,a:" + a);
            return "123456";
        }
    }

    package com.mayikt.method;
    
    import com.mayikt.service.MessageInterface;
    
    /**
     * @ClassName Test013
     * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com
     * @Version V1.0
     **/
    public class Test013 {
        public static void main(String[] args) {
            Test013 test013 = new Test013();
    //        MessageInterface messageInterface = new MessageInterface() {
    //
    //            @Override
    //            public String get(Integer a, Integer b) {
    //                return test013.objGet(a, b);
    //            }
    //        };
    //
    //        String s = messageInterface.get(1, 2);
    //        System.out.println(s);
    
    //        MessageInterface messageInterface2 = (a, b) -> test013.objGet(a, b);
            MessageInterface MessageInterface3 = test013::objGet;
            String s = MessageInterface3.get(1, 2);
            System.out.println(s);
        }
    
        public String objGet(Integer a, Integer b) {
            System.out.println("objGet,a:" + a + ",b:" + b);
            return a + b + "";
        }
    }
  • 相关阅读:
    C#中Split用法
    ASP.NET Get和Post两种提交的区别:
    BAT常用命令
    SQL语句:在两个数据库间复制表结构和数据数据库
    C#中Array与ArrayList用法及转换
    找出输入区间内的回文质数
    (转)加藤嘉一:中国大学生,你没资格抱怨政府
    最长公共子序列(LCS)
    shell(希尔)排序
    关于Ubuntu中google chrome浏览器字体的设置
  • 原文地址:https://www.cnblogs.com/angdh/p/15596553.html
Copyright © 2011-2022 走看看