3

I'm writing some aspect for our system's method input validation:

  1. Every method's return object all derived from a common base class which has a property holds return code.
  2. Pointcut defines which package to intercept
  3. Write aspects doing validation of method's input. If validation succeeded, proceed() to execute method. If failed, set the return code property of method's returning object and returns directly.

My question is: How to get the real return object class besides the base class? I can only know the base class I should return but not the real class. I found nothing in ProceedingJointPoint, getSignature() only has class name...

4

1 に答える 1

2

メソッドの戻り値の型を取得するには、ProceedingJoinPoint の署名を MethodSignature にキャストする必要があります ( http://www.eclipse.org/aspectj/doc/next/runtime-api/org/aspectj/lang/reflect/MethodSignature.html)。これにより、.getReturnType() メソッドが提供されます。これにより、必要なものが正確に得られるはずです。

于 2013-03-21T09:13:18.977 に答える