I can\'t figure out a use case for being able to annotate interfaces in Java.
Maybe someone could give me an example?
I mark my interfaces with @Immutable to clearly indicate to developers of subclasses which Mutability contract a class implementing the interface should have. As gehel puts it, programming by contract.
More an example, but Local and Remote annotations in EJB3. According to the java doc,
When used on an interface, designates that interface as a local business interface.
I guess the use case here is that the interface has a special function best denoted by an annotation.
I have used it when defining a REST interface. RESTeasy allows you to create REST client that uses an annotated interface (RESTInterfaceV1 in this example):
final RESTInterfaceV1 client = ProxyFactory.create(RESTInterfaceV1.class, "http://localhost:8080/rest");
Although the annotations have to be duplicated on object that actually implements the REST interface, the interface itself can be distributed separately to those wanting to make a Java REST client.
I use findbugs extensively. I find the use of annotations to specify Nullity constraints very useful. Even if you dont actually use findbugs, it makes the intent of the code much clearer. Those annotations have their place on Interfaces as much as Classes. You could argue that it is kind of programming by contract ...