Re-specification and re-abstraction
David Holmes
david.holmes at oracle.com
Wed Dec 21 21:45:15 PST 2011
One of the things that concerns me in the current State of the Lambda is
the fact that re-specification of method on a sub-interface does not
re-abstract the method, but continues to allow any default from a super
interface to be applied to that method. This is inherently wrong in my
opinion.
Consider this fictitious but plausible example.
We have the present Map interface. We also have a ConcurrentMap
interface that adds some additional methods that provide atomicity for
compound actions on maps that support concurrent access.
Suppose that ConcurrentMap actually re-specified each of the Map methods
to add various thread-safety and atomicity guarantees.
Now suppose that the maintainer of Map decides to take advantage of
default methods and adds default implementations to some of those Map
methods. This is not done with ConcurrentMap in mind and those
implementations offer no specific thread-safety or atomicity guarantees.
It should be obvious that those implementations are not likely to be
valid for any class that implements ConcurrentMap.
Given the current semantics however, if I were to write a class that
implements ConcurrentMap and accidentally forgot to implement those
methods for which a default exists in Map, then my class will in fact
"inherit" those implementations. And in doing so my class would be
completely broken, but I would be unaware of it.
To me this is completely wrong - we should never sacrifice correctness.
A supertype does not in general know about any subtypes and so a
supertype's default implementation should not apply if the subtype has
redefined that method. Any change to the "documentation" of a method is
a change to its specification. Only the author of that change is in a
position to say whether a default implementation in a supertype is still
applicable - so to assume that it is by default (no pun intended) is
just wrong in my view.
If redefinition of a method always re-abstracted it then, I think, no
explicit syntax for re-abstraction would be needed.
David Holmes
More information about the lambda-dev
mailing list