I'd say the reason is that otherwise a multiple-inheritance problem would occur.
Example:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD) @Inherited
public @interface Baz { String value(); }
public interface Foo{
@Baz("baz") void doStuff();
}
public interface Bar{
@Baz("phleem") void doStuff();
}
public class Flipp{
@Baz("flopp") public void doStuff(){}
}
public class MyClass extends Flipp implements Foo, Bar{}
If I do this:
MyClass.class.getMethod("doStuff").getAnnotation(Baz.class).value()
what's the result going to be? 'baz', 'phleem' or 'flopp'?
For this reason, annotations on interfaces are rarely useful.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…