Private interface methods, example use-case?

后端 未结 3 1038
借酒劲吻你
借酒劲吻你 2020-12-30 19:36

\"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 with

3条回答
  •  攒了一身酷
    2020-12-30 20:31

    Interfaces can now have default methods. These were added so that new methods could be added to interfaces without breaking all classes that implement those changed interfaces.

    If two default methods needed to share code, a private interface method would allow them to do so, but without exposing that private method and all its "implementation details" via the interface.

提交回复
热议问题