default keyword is harmful was Re: Default method survey results
Rémi Forax
forax at univ-mlv.fr
Fri Aug 17 05:39:42 PDT 2012
In fact, the keyword 'default' is harmful in my opinion, because it
focus the user attention on the method but the thing that change in Java
8 is the way a concrete class get the code of all it's method. Or said
differently, a method marked with the keyword 'default' is still abstract.
interface I {
default void m() { ... }
}
I i = ...
i.m(); <--- still an abstract call
If we had a keyword to put somewhere is where you implement that
interface, because now you can get code from that interface.
People will be more surprised not when they will see code in interface but
when their favorite IDE will not list Iterator.remove() has a method
to implement when creating an inner class of an Iterator.
Another way to see the problem is to think about the reflection API.
Should we have a method getDefaultMethods() in java.lang.Class or a
isDefault() on j.l.r.Method ?
I think the answer is no,
because exactly like their is no way to do the equivalent code of
super.m() with the reflection API,
they should be no way to directly call the code of a method in an
interface (I.super.m()).
cheers,
Rémi
More information about the lambda-dev
mailing list