我有一个方面(用 aspectj 语法编写public aspect ....
),它操纵许多返回 a 的方法的结果,Collection
以便对结果进行分页。
我不能(或者我不知道如何)在建议中使用泛型,所以无论我调用建议的方法之一,我都会收到警告
unchecked conversion when advice applied at shadow method-call(java.util.Collection ...), expected java.util.Collection<T> but advice uses java.util.Collection [Xlint:uncheckedAdviceConversion]
我怎样才能摆脱这个?
斯特凡诺
-- 添加方面代码摘录
public aspect PaginationSupportAspect extends ServiceSupportAspect {
private static final Logger log = LoggerFactory.getLogger(PaginationSupportAspect.class);
private pointcut paginate(Criteria criteria) : call(Collection org.jcz.persistence.Service+.*(Criteria));
@SuppressWarnings({ "unchecked", "rawtypes" })
Collection around(Criteria criteria, Service service) : paginate(criteria) && target(service) {
log.trace(String.format("Executing <%s> @ <%s>", this.getClass(), thisJoinPoint.toLongString()));
return doPaginate(proceed(criteria, service), criteria.getPagination(), service);
}
/**
*
* @param source
* @param criteria
* @return
*/
private <T extends EntitySupport> Collection<T> doPaginate(Collection<T> source, Pagination pagination, Service<T> service) {
// IMPLEMENTATION OMITTED BECAUSE IT'S QUITE LONG
// What it does is to create another Collection<T> that holds the pagination coordinates (page number, size, count)
// and only the elements of the requested page
}
}
使用示例
Collection<MyEntity> entities = myEntityService.findAll(criteria);
这就是我收到警告的地方