import java.util.*; import org.aspectj.lang.annotation.SuppressAjWarnings; public aspect AfterReturningExamples { after() returning : execution(* C.*(..)) { System.out.println(thisJoinPointStaticPart); } pointcut executionOfAnyMethodReturningAList() : execution(List *(..)); // matches all three after() returning(List listOfSomeType) : executionOfAnyMethodReturningAList() { for (Object element : listOfSomeType) { System.out.println("raw " + element); } } // matches bar and goo, with unchecked on goo after() returning(List listOfDoubles) : execution(* C.*(..)) { for(Double d : listOfDoubles) { System.out.println("a1 " + d); } } // matches only bar after() returning(List listOfDoubles) : execution(List C.*(..)) { for(Double d : listOfDoubles) { System.out.println("a2 " + d); } } // matches bar and goo, with no warning @SuppressAjWarnings after() returning(List listOfDoubles) : execution(* C.*(..)) { for(Double d : listOfDoubles) { System.out.println("a3 " + d); } } public static void main(String[] args) { List ld = new ArrayList(); ld.add(5.0d); ld.add(10.0d); List ls = new ArrayList(); ls.add("s1"); ls.add("s2"); C c = new C(); c.foo(ls); c.bar(ld); c.goo(ld); } } class C { public List foo(List listOfStrings) { return listOfStrings; } public List bar(List listOfDoubles) { return listOfDoubles; } public List goo(List listOfSomeNumberType) { return listOfSomeNumberType; } }