zoukankan      html  css  js  c++  java
  • java9新特性-7-语法改进:接口的私有方法

    1.官方Feature

    213: Milling Project Coin

    Support for private methods in interfaces was briefly in consideration for inclusion in Java SE 8 as part of the effort to add support for Lambda Expressions, but was withdrawn to enable better focus on higher priority tasks for Java SE 8. It is now proposed that support for private interface methods be undertaken thereby enabling non abstract methods of an interface to share code between them.

     


    2.使用说明

    Java 8中规定接口中的方法除了抽象方法之外,还可以定义静态方法和默认的方法。一定程度上,扩展了接口的功能,此时的接口更像是一个抽象类。

    在Java 9中,接口更加的灵活和强大,连方法的访问权限修饰符都可以声明为private的了,此时方法将不会成为你对外暴露的API的一部分。

     


    3.使用举例

     
     
     
     
     
     
     


    作者:尚硅谷面试官宋红康
    链接:https://www.jianshu.com/p/ba217038abb4
    來源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 相关阅读:
    背景不动,内容滚动的解决方案(移动端)
    移动端真实1px的实现方法
    用户模板和用户场景
    构建之法阅读笔记02
    学习进度六
    NABCD
    构建之法阅读笔记01
    学习进度五
    梦断代码阅读笔记03
    地铁系统
  • 原文地址:https://www.cnblogs.com/wzlbigdata/p/8278380.html
Copyright © 2011-2022 走看看