Java Custom Annotations

Hello All,

I am learning about custom annotations.

I would want my custom annotation to find the method name on which it is annotated. Similar to @override as in the example below,

@Override
public void whoAmI();

Without passing the method name, Java recognizes the method name whoAmI() and it looks whether this method declaration is present in interface.

Similar to this, my custom annotation would need to recognize the method name directly, instead of iterating all the methods using getDeclaredMethods() and looking for the method with my custom annotation.

Could anyone please help?

Thanks

Oracle has an annotations tutorial:

Usually, these are implemented as annotations processors. You can probably google “Java annotation processor” to see some examples and get inspired.