Search code examples
javainterfaceannotationslanguage-features

What's the difference between interface and @interface in java?


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.


Solution

  • 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.