I'm trying to create an AspectJ Aspect to intercept the returning methods that has a generic interface.
This is my AspectJ
@AspectJ
public class MyAspect {
    @AfterReturning("execution(java.util.Collection+<mypackage.MyAbstractEntity+> mypackage.mvc.controllers..*.*(..))", returning = "list")
    public doStuff(JoinPoint j, Collection<MyAbstractEntity> list) {
    }
}
and this is my class that I want to weave into:
package mypackage.mvc.controller;
public class MyController {
    // MyEntity extends MyAbstractEntity
    public List<MyEntity> findAll() {
    }
}
What am I doing wrong?
Solved!
Put the "plus" after the generics definition ("plus" means "classes that extends it"):
java.util.Collection<mypackage.MyAbstractEntity+>+
And contract the "list" as "? extends":
public doStuff(JoinPoint j, Collection<? extends MyAbstractEntity> list) {
The code will look like this:
@AspectJ
public class MyAspect {
    @AfterReturning("execution(java.util.Collection<mypackage.MyAbstractEntity+>+ mypackage.mvc.controllers..*.*(..))", returning = "list")
    public doStuff(JoinPoint j, Collection<MyAbstractEntity> list) {
    }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With