开发者

Annotate Java method for logging its result and exceptions

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜