Reputation: 19569
I'm looking for the implementation of @interface. But it seems the @interface don't need an implementation.
Those annotations just carry information for compiler's checking. and the compiler will put those information to class file. then we use byte code reader or reflection API to read those information back.
Is right of my understanding ?
Upvotes: 1
Views: 462
Reputation: 29959
I'm looking for the implementation of @interface. But it seems the @interface don't need an implementation.
If you literally mean the language construct @interface
, then you should note that it isn't an annotation itself, it just looks similar. It's a keyword used when defining annotation types. It actually are two tokens, @
and interface
that can have whitespace in between. See: Java 7 Language Specification - 9.6. Annotation Types
Those annotations just carry information for compiler's checking. and the compiler will put those information to class file. then we use byte code reader or reflection API to read those information back.
Correct, annotations are just meta data, they never do anything by themselves. The visibility depends on the Retention meta-annotation. Depending on the retention policy, they can be made visible to the runtime using reflections or restricted to the source code, so they won't be included in the bytecode. The most common way probably is to use reflections, another way is to use an annotation processor before compilation.
Upvotes: 1