Reputation: 13568
I see that @Interface is used to declare an annotation. Can @Interface be used to declare something other than an annotation as well?
If not, why not just call it @Annotation or something?
Upvotes: 0
Views: 56
Reputation: 718886
I see that
@Interface
is used to declare an annotation.
Actually, it is @interface
and the distinction is important; see your other Question.
If not, why not just call it @Annotation or something?
Because they didn't.
Because Annotation
would violate the style rules (as an identifier)
Because annotation
was not reserved as a keyword. Turning it into a keyword would potentially make lots of existing customer Java code non-compilable.
(That is what they did with enum
and it caused problems for some people. It would cause more problems in this case ... because the amount of existing legacy Java code has grown in the last ~15 years.)
Seriously, there is little point asking questions of the form "why didn't they design Java the way that I would have done it?". They won't actually help you in doing your job ... unless your job is designing programming languages. And if it is, then you probably already understand that it is impossible to resolve conflicting PL design requirements in a way that satisfies everyone.
Upvotes: 0
Reputation: 13427
Can there be Java interfaces that aren't annotations?
Yes, regular interface
s:
public interface MyInterface {...}
Can @Interface be used to declare something other than an annotation as well?
No, @interface
defines an annotation. And be careful with the letter case - it's smallcase @interface
, not @Interface
.
why not just call it @Annotation or something?
Because annotations are a type of interface, see the answer I gave to your other question,
An annotation type declaration specifies a new annotation type, a special kind of interface type.
(bold emphasis is mine) and from the tutorial:
Annotation types are a form of interface
Upvotes: 1