"default" keyword inconsistency: *before* default methods in interfaces, *after* default attributes in annotations
Remi Forax
forax at univ-mlv.fr
Fri Feb 8 06:54:20 PST 2013
On 02/08/2013 03:42 PM, Rogerio Liesenfeld wrote:
> Hello,
>
> In lambda_b75, I noticed that the “default” keyword is being used
> *before* the method name in default method declarations inside
> interfaces.
> This contradicts current usage of the same keyword in annotation
> types, where it must appear *after* the method name. This is since
> Java 5.
>
> For example, consider the following annotation type declaration:
>
> public @interface RequestForEnhancement {
> int id();
> String engineer() default "[unassigned]";
> }
>
> Attributes like “engineer” above are similar to default methods such as:
>
> public interface RequestForEnhancement {
> int id();
> default String engineer(){ return "[unassigned]"; }
> }
>
> It would be more consistent with “default” after the method.
>
We are well aware of that :)
default after a method in an annotation is for specifying a default
value and default before is for saying that the method will be used if
the class doesn't provide one.
So it's not the same semantics, so it should not be 'consistent'.
Now, re-using the same keyword for 2 different concepts is troublesome
for rookies,
Java has a long tradition of doing that, e.g. final on class and final
on field,
and it seems we are not able to get that.
Rémi
More information about the lambda-dev
mailing list