How to define a java Annotation, that gets to an overridden method automatically?

StackOverflow https://stackoverflow.com/questions/23680946

  •  23-07-2023
  •  | 
  •  

سؤال

I'd like to create a custom Java Annotation, which can be applied to a method in an interface. What I'd like is, that when I override the method, that belongs to that interface, an annotation gets above the overridden method automatically.

This is my very simple interface, used for callback:

public interface ChangeToArcherNotifier {
    public void ChangeToArcher();
}

And when I implement it, I want that method to be marked with an annotation, like this:

@Callback
@Override
public void ChangeToArcher() {

}
هل كانت مفيدة؟

المحلول

You cannot do this. If you program in Notepad e.g., who do you expect to paste the annotation name above the method in the source file of the class implementing the interface? This is up to your IDE (if the IDE supports such a feature).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top