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.使用举例


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Laura, one of my great friends got married today. Her fam...
    doooodles阅读 432评论 9 9
  • “是是是。”那许强马上让开路让刘云帆过去。 刘云帆走上前,目光微微一瞥,发现地上那女子竟然是个大美女。那个女子有一...
    飄雲阅读 204评论 0 1
  • 今天我问家里面拿生活费,我妈妈、姐姐、姐夫都分别给了钱我。当时我看见我姐夫都给了我,我还是挺吃惊的(因为我接触我姐...
    真实的面具阅读 169评论 0 0
  • 文/花语-蝴蝶兰之语 沉浸在爱且以爱拥抱一切,爱上每一个人、每一个地方或每件事,包括你的念头。让充沛的爱以「谢谢你...
    花语_蝴蝶兰之语阅读 867评论 6 14