美文网首页
java语法糖

java语法糖

作者: 简书徐小耳 | 来源:发表于2019-04-23 13:29 被阅读0次

    @FunctionalInterface注解修饰的接口A必须只有一个方法
    其他普通方法可以通过::调用自身的方法,并且返回A,这就是类似于把A的方法实现了,具体的执行逻辑就是,通过::调用的方法。

    @FunctionalInterface
    public interface Bin {
        void say();
    }
    public class B {
        void endWith() {
            System.out.println("endWith=====");
        }
    
        public static void main(String[] args) {
            B b = new B();
            Bin bin = b.get();
            bin.say();
        }
    
        public Bin get() {
            return this::endWith;
        }
    }
    

    相关文章

      网友评论

          本文标题:java语法糖

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