开发者

Annotate Java method for logging its result and exceptions

开发者 https://www.devze.com 2023-04-12 19:38 出处:网络
Is it possible to log result,that method returned with annotation? or specific Exceptions,that was thrown by method?

Is it possible to log result,that method returned with annotation?

or specific Exceptions,that was thrown by method?

Can't find return value for method m or something like that ,using this call:

for (Method m : Class.forName("AnnotatedBe开发者_JS百科an").getMethods()) {
  ...
}

AnnotatedBean is class,which methods annotated by custom annotation.


Is it possible to log result,that method returned with annotation? or specific Exceptions,that was thrown by method?

This seems textbook example of separation of concerns. Take a look at AspectJ; production aspects can work very well in this situation.

Can't find return value for method m or something like that ,using this call:

Now I am confused. How can return value "not be found"?


Can't find return value for method m or something like that ,using this call:

You need to invoke the method to get a return value back.

for (Method m : Class.forName("AnnotatedBean").getMethods()) {
    Object returnValue = m.invoke(instance, args);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号