lundi 17 mai 2021

Simple Java Annotation [closed]

My friend and I would like to create a very simple Java annotation (for methods) which will print something simple for every method which is annotated. For example: “This method is annotated with MyCustomAnnotation” (We would then like to add a few stack-trace elements to this printout, so it needs to be flexible enough for this).

What is the simplest code to achieve this?

Our objective is as follows... invoking the following method:

@MyCustomAnnotation
    public static int sayBlahAndReturnOne() {
        System.out.println("blah");
        return 1;
    }

would give the following output:

“This method is annotated with MyCustomAnnotation”
“blah”

How do we achieve this? What would the @interface annotation look like?





Aucun commentaire:

Enregistrer un commentaire