0

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("AnnotatedBean").getMethods()) {
  ...
}

AnnotatedBean is class,which methods annotated by custom annotation.

2 Answers 2

3

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"?

Sign up to request clarification or add additional context in comments.

5 Comments

"return value" - here I mean to log the result of the method
should I use AspectJ mandatory instead of standard ways? what is good practice now?
I don't know what is "mandatory instead of standard ways". I believe production aspects are idiomatic for separation of concerns. My point is basically...whatever works, is easy to implement and least error prone.
i mentioned,what is best practice for now
sorry..there is some communication gap :) I understand that you are asking what is currently considered best practice, but I am unable to understand what you mean by "using AspectJ mandatory" and by "using AspectJ in standard ways". If by mandatory you mean that it is wired into the application (as against being optionlal) then yes, I believe hard-wiring aspects is quite the norm, and known as production aspects
1

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);
}

2 Comments

matt,can the invoke() method slowdown my application? that i'm afraid of.I mean,is method ran twice in runtime in this case?
I'm not sure what you mean. Method.invoke() calls the actual method, which seems necessary if you want to log it's result in some sort of aspect such as this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.