1

I mean I know that it provides metadata and special instructions to the compiler but where is the logic for that? How are two annotations different if both of them has same body? The source code for @Id, @Override and @Embeddable is same but how do they work differently when they don't have any code in them. Also, if we can't see the code/logic then how can I create my own annotation with specific functionality?

v0ld3m0rt
  • 866
  • 3
  • 12
  • 47
  • 4
    Annotations have no logic, they are just annotations. Any logic associated with an annotation is brought either by code using reflection, or by an annotation processor (or in the case of annotations like `@Override`, the Java compiler). – Mark Rotteveel Jul 12 '22 at 10:14
  • It's not the annotation that tells the compiler to do something, no, the compiler knows about the `@Override` annotation - and handles that case. – Johannes Kuhn Jul 12 '22 at 10:14
  • It's what uses them that count. For example if you annotate a class member, and you pass an instance of that class to a method that expects members to be annotated with a certain annotation, that method checks whether a member is annotated and does stuff. – Federico klez Culloca Jul 12 '22 at 10:15
  • The first article keep referring to some link provided by Jean-Philippe. But there isn't any user or any link provided into it. I've read both of the links and still it's not clear to me. – v0ld3m0rt Jul 12 '22 at 10:33

0 Answers0