JoinPoint Matching Covariant methods
April 23, 2010 Leave a comment
AspectJ JoinPoint matches methods with Covariant return types. The ‘declare warning’ construct seems to be a useful way of testing because the eclipse markers show the match.

Aspect
declare warning: execution(Collection<? extends Test> *.test( .. )) : "Covariant";
package com.test;
import java.util.Collection;
public class CovariantSub extends CovariantSuper{
public Collection<Test> test(){
return null;
}
@SuppressWarnings("unchecked")
public Class test1(){
return null;
}
}
package com.test;
import java.util.Collection;
public class CovariantSuper {
public Collection<? extends Test> test(){
return null;
}
public Class<?> test1(){
return null;
}
}