Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Updating a returned variable

Hi Breaks,
you can do this, again, with an around advice :

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

Object around() : executionOfMyMethod() {
  MyObject ret = proceed();
  ret.setAge(27);
  return ret;
}




breaks wrote:
> Hi,
> Simple question time! Can I update a property on a returned object with an
> aspect.
>
> Suppose I have a method:
>
> public MyObject myMethod() {
>     // Code which changes MyObject
> }
>
>
> I wish to have an aspect which will change a property on MyObject. I know I
> can use an around advice, can be used to return a specific MyObject
> reference, but I want to get the existing MyObject reference and just change
> a property on it, something like
>
> myObject.setAge(27);
>
> I don't want to change anything else.
>
> Any ideas? 
>
> Thanks
>
>
>   



Back to the top