[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Updating variable in the middle of a method

Hi Breaks,
you can use an around advice :

pointcut executionOfMyMethod() : execution(public StringBuffer
TheClass.myMethod());

Object around() : executionOfMyMethod() {
  StringBuffer sb = new StringBuffer();
  sb.append(123);
  return sb;
}

There is no way to access a variable declared inside a method.

This also relates to your next question.

Hope this helps,
Simone

breaks wrote:
> Hi
> Suppose I have a method like the following:
>
> public StringBuffer myMethod() {
>      StringBuffer sb = new StringBuffer();
>      sb.append("1");
>      sb.append("2");
>      return sb.toString();
> }
>
> I want to update this to always return 123.
> I would like to do this via an execution pointcut (I don't want to use call)
> so I need do get a handle to the sb variable?  Any ideas how this can be
> done.
>
> Thanks a million.
>
>  
>
>