On 08/08/2012, Russel Winder <[address removed]> wrote:
> Duly answered. One question though: Why have them at all? Java has
> abstract classes which can be used as types. Interfaces with default
> methods appears to implement the same idea. Introducing a second way of
> achieving a goal sounds very Perlesque.
Java `interface` has become a popular feature because they express
they idea of a type with guaranteed no implementation (beyond jlo).
The unfortunate part comes because it is inevitable that you'll want
to add methods to some successful interfaces. Switching to an abstract
class causes almost complete binary incompatibility issues and some
minor source issues (and naming issues if you use *that* convention).
JDBC adds methods to interfaces but has been called "special", and
other less kind things.
The particular issue comes with ("new") Java collections. This is
despite claims that complete upfront design is great for APIs. From
1.2 - introduced (does have Collections static utils)
1.3 - no problem
1.4 - necessary to introduce separate concurrent interfaces
1.5 - SimpleIterator has to be scraped; posh for loops require a
1.6 - NavigableMap introduced to enhance SortedMap (and Sets)
1.7 - no problems that I can remember at the moment
1.8 /1.9 - want to add support for use under the Fork-Join framework
You probably aren't going to use FJ on, say, some random List returned
by some random library, so it's not strictly speaking necessary
introduce these 1.8 methods directly into the collection interfaces.
If you replaced, say, `private final List...` with `private final
ArrayList...` that would be sufficient. Perhaps introduce a new
tersely-named, (initially pure) abstract class to correct the library
flaw, `private final Ls...`. Instead it has been decided "co-evolve"*
language & library by adding implementation to Java `interface`.
(Brian has asked for positioning of default not to be openly discussed
whilst the vote is live. I think it would have been wise to discuss it
beforehand, because I've changed my mind.)
*Not evolution as in natural selection.