←Older revision | Revision as of 05:59, 22 December 2021 | ||
Line 1: | Line 1: | ||
[[DefaultMethods]] is a new feature of [[JDK]]8. It allows one to specify ('''default''') implementation of [[Java]] '''interface''' method. | [[DefaultMethods]] is a new feature of [[JDK]]8. It allows one to specify ('''default''') implementation of [[Java]] '''interface''' method. | ||
- | Adding methods with some implementation breaks the clear separation between [[Java]] '''interface''' (used to specify a contract only) and '''class''' (provides some implementation). Many members of the [[Java]] community were crying for having a way to add methods into already published '''interface''' in a [[BackwardCompatibility|backward compatible]] way for ages. Of course, as usual in [[Java]], only when the [[JDK]] team felt the need itself (because of adding a lot of new [[Lambda]] methods into {{JDK|java/util|Collection}} & co. classes), it listened to the general request. | + | Adding methods with some implementation breaks the clear separation between [[Java]] '''interface''' (used to specify a contract only) and '''class''' (provides some implementation). Many members of the [[Java]] community were crying for having a way to add methods into already published '''interface''' in a [[BackwardCompatibility|backward compatible]] way for ages. Of course, as usual in [[Java]], only when the [[JDK]] team felt the need itself (because of adding a lot of new [[Lambda]] methods into {{JDK|java/util|Collection}} & co. classes), it became [[pragmatic]] and listened to the general request. |
On the other hand, there were people claiming that [[DefaultMethods]] are bad - that an interface should be a code-less specification and the change would have consequences. And yes, it does. This page describes some of them. | On the other hand, there were people claiming that [[DefaultMethods]] are bad - that an interface should be a code-less specification and the change would have consequences. And yes, it does. This page describes some of them. |