Picco
Picco

Reputation: 67

Design a custom annotation to invoke a method in a jar

I'm a bit new to annotations in Java. Is it possible to design a custom annotation which when used in a class automatically invokes a method present inside another Class. TIA.

Upvotes: 0

Views: 623

Answers (1)

GhostCat
GhostCat

Reputation: 140613

The answer is "sort of": annotations by themselves do nothing (except "compile time" annotations that affect the compile process).

Meaning: just attaching an annotation to something doesn't magically cause a method to be called at some arbitrary point in time.

This works differently: you have some sort of framework - and at some point you ask the framework to process an object, class, ... And then the framework might check for the presence of certain annotations to "do" something based on that check.

Thus: it is possible to implement custom annotations, and it is also possible to make some "framework" react to the presence of that annotation.

In case you find this answer too generic - well, it can't be more precise/specific than the question ...

Upvotes: 1

Related Questions