why Interface Default methods?

后端 未结 3 1595
时光取名叫无心
时光取名叫无心 2021-02-07 12:53

Learning java 8 default methods . This link like any other resource on internet says

In ‘the strictest sense’, Default methods are a step backwards beca

3条回答
  •  终归单人心
    2021-02-07 13:25

    If there is a requirement to add new method to an interface, clients which use existing interface will be broken as classes needs to implement all methods in the interface.

    In this scenario, default and static methods can be used. These methods can have body and clients don't need to implement them, so existing implementations work without any changes.

    For example, if you want to enhance interfaces to add methods which accept lambda expressions, you can use default methods.

提交回复
热议问题