【发布时间】:2016-04-26 15:17:44
【问题描述】:
看来我又被 java 泛型困住了。这是我所拥有的:
几个类:
class CoolIndex implements EntityIndex<CoolEntity>
class CoolEntity extends BaseEntity
使用上面的类枚举:
enum Entities {
COOL_ENTITY {
@Override
public <E extends BaseEntity, I extends EntityIndex<E>> Class<I> getIndexCls() {
return CoolIndex.class;
}
@Override
public <E extends BaseEntity> Class<E> getEntityCls() {
return CoolEntity.class;
}
}
public abstract <E extends BaseEntity, I extends EntityIndex<E>> Class<I> getIndexCls();
public abstract <E extends BaseEntity> Class<E> getEntityCls();
}
我需要使用getIndexCls()函数调用的结果来调用函数:
static <E extends BaseEntity, I extends EntityIndex<E>> boolean isSomeIndexViewable(Class<I> cls)
问题是编译器抱怨return CoolIndex.class; 和return CoolEntity.class;,我不清楚为什么...当然我可以将它转换为Class<I>(第一种情况),但在我看来我是试图掩盖我的误解,感觉不对。
【问题讨论】:
-
相关(可能有帮助):stackoverflow.com/q/20973221/1225328