Writing a java annotation for timing method call

后端 未结 9 1416
逝去的感伤
逝去的感伤 2020-12-24 12:17

I want to write a java annotation which times the method call. something like this:

@TimeIt
public int someMethod() { ... }

and when this m

9条回答
  •  梦毁少年i
    2020-12-24 12:42

    Simply put: you can't!

    Annotations are not pieces of code that get automatically started together with your code, they are just annotation, pieces of information that can be used by other programs working on your code like loading or running it.

    What you need is AOP: aspect oriented programming.

提交回复
热议问题