Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Wildcard return type on around advice

You can use "Object" as the return type of the around advice. Object is 
treated specially when used as the return type of the around advice, and 
the value returned from the around advice will be exactly what the caller 
is expecting. This facility was added to the language to support writing 
generic (around) advice against a wide variety of join points with 
differing return types. It even works with primitive types (from before 
Java 5 came along with autoboxing....).

-- Adrian
Adrian_Colyer@xxxxxxxxxx



"Nitzan Volman" <nitzan@xxxxxxxxxxx> 
Sent by: aspectj-users-admin@xxxxxxxxxxx
16/01/2005 12:10
Please respond to
aspectj-users@xxxxxxxxxxx


To
<aspectj-users@xxxxxxxxxxx>
cc

Subject
[aspectj-users] Wildcard return type on around advice






Hi, 
I would like to create around advice for access of objects that extend 
certain type:
    pointcut myPointcut(Object owner) :
             target(owner)
             get(private MyObject+ my.pckg.*.*);

    ???? around(Object owner) : myPointcut(owner) {
             proceed(owner).doSomthingOnMyObject();
    }

The return type of the around advice is a problem here, it should be an 
exact match to the type in the join points.
This is a compiler error I got when attempting to declare MyObject as the 
return type of the advice: "[error] This method must return a result of 
type MyObject" 
I want to intercept every get access to members of "owner" that extend a 
certain type - and to define one type of advice for all of them.
btw, this can be easily done with "set" access.
My current solution uses the same pointcut, "after" advice and accesses 
the member using reflection (to the field named: 
thisJoinPointStaticPart.getSignature().getName())
Is there currently any way to define a wildcard return type? Will this 
ever be supported? Is there a better way to do this?
Thanks,
/Nitzan



Back to the top