Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Adding default methods to interfaces, what's CDT's policy?

Hi,


according to

https://wiki.eclipse.org/Evolving_Java-based_APIs_2#Evolving_API_Interfaces

adding a default method to an existing interface (that is implementable),

is a breaking API change.  The rule does provide an 'exception' if the benefit is felt

to outweigh the risk. See below for explanation.


I find using default method makes the code much simpler (avoiding interface2, interface3, interface4, etc).


What do others feel we should do?  Should it be on a case-by-case basis (I find that hard to establish)?

Or should we have a recommended, or allowed approach?


Thanks


P.S. We have such changes in 9.2


P.P.S. The explanation from that wiki about why the default breaks the API.


(8) Adding a default method will break an existing client type if it already implements another interface that declares a default method with a matching signature, and the client type already refers to the default method from the other interface (except when using the Interface.super.method() notation). The added default method will cause an IncompatibleClassChangeError at run time, see JLS8 13.5.6 (http://docs.oracle.com/javase/specs/jls/se8/html/jls-13.html#jls-13.5.6). Furthermore, re-compiling the type will result in a compile error.

In cases where the risk of multiple inheritance of the same method from multiple interfaces is deemed low and the added value is deemed sufficiently high, selected default methods can be added to existing interfaces. However, such a change should only be applied in an early milestone, and it should be reverted if clients report any difficulties with the change.


Back to the top