Defender methods and compatibility
brian.goetz at oracle.com
Sun Nov 28 16:23:32 PST 2010
>>> Anyway, the good news is that mod-extn _is_ SC. That's true whether a
>>> default is specified in the interface via a method body or a method name.
>> Should have said: mod-extn _may be_ SC. When an implementation class
>> doesn't override the extension, it's possible for previously-identical
>> extension methods to diverge (i.e. one changes its default) and break SC.
> Understood. That is the particular part of the specification that I take
> issue with. mod-extn (changing the code of a default method) should (in my
> opinion) always be source compatible, as the code of a method is a prime
> example of an implementation detail.
Sorry for the delay in responding on this: have been on holiday.
The code of the default method *is* an implementation detail. However, the identity of the default method is not. You can consider it to be a new dimension of the signature, if you like; it is part of the inheritance metadata. I can see why you would want to consider it an implementation detail -- I wanted to initially as well -- but that's not really how this feature works.
But the limitations on SC are not new. We're used to having certain "subject to" caveats in the definition of SC. For example, add-meth is SC, but in reality only to a point: if the newly added method would cause an illegal override in a subclass, then it is not SC, but this a minor enough consideration to be swept under the rug via an asterisk and we consider add-meth to be source compatible. (Note that the conflict may be with an implementation not known to the class being modified.)
The exact same sort of caveat is in operation for mod-extn. mod-extn is source-comptable, except when it causes a conflict with a subclass that inherits the method *and* the same method with a different default from another (unknown to the modified interface) interface. While this sort of conflict may well be more likely than the sort in the previous example (or may not, we're not sure yet), it is definitely of the same flavor.
More information about the lambda-dev