views:

274

answers:

3

I haven't touched Java since using JBuilder in the late 90's while at University, so I'm a little out of touch - at any rate I've been working on a small Java project this week, and using Intellij IDEA as my IDE, for a change of pace from my regular .Net development.

I notice it has support for adding interfaces and @interfaces, what is an @interface, and how does it differ from a normal interface?

public interface Test {
}

vs.

public @interface Test {
}

I've done a bit of searching, but couldn't find a great deal of useful info referring to @interface.

+9  A: 

The @ symbol denotes an annotation type definition.

That means it is not really an interface, but rather a new annotation type -- to be used as a function modifier, such as @override.

See this javadocs entry on the subject.

MrKishi
+1 You type faster than me! hehe
victor hugo
Great thanks, good to know. So what was the rationale for calling it @interface, rather then say @annotation I wonder.. seems like an unnecessarily overloaded term.
Bittercoder
The tutorial and the JLS allude to an annotation being a special kind of interface. There doesn't appear to be much discussion out there on the subject, but http://javarunner.blogspot.com/2005/01/annotations-in-java-15.html explains that annotations are an implicit extension of the Annotation interface and @ and interface are used to together differentiate from a regular interface. You may also want to read the JSR specification for annotations.
DavidValeri
+5  A: 

The interface keyword indicates that you are declaring a traditional interface class in Java.

The @interface keyword is used to declare a new annotation type.

See Sun tutorial on annotations for a description of the syntax.

See the JLS if you really want to get in to the details of what @interface means.

DavidValeri
A: 

I stopped using Java when c# was born

Annotation are just metadata for use in reflection etc

Just like attributes in c#

TFD