编译环境
gradle JavaCompile
jdk1.8
代码
public abstract class NodeService<T extends NodeInterface>{
private Mirror<T> mirror;
public NodeService() {
try {
Class<T> entryClass = (Class<T>) Mirror.getTypeParam(getClass(),0);
mirror = Mirror.me((Class)NodeInterface.class);
}
catch (Throwable e) {
log.warn("!!!Fail to get TypeParams for self!", e);
}
}
}
错误日志
E:\environment\ideaworkspace\csaserver\build\compile\com\cloudmap\csmc\kernel\asset\service\group\NodeGroupService.java:69: 错误: 不兼容的类型: Class<Object>无法转换为Class<T>
Class<T> entryClass = (Class<T>) Mirror.getTypeParam(getClass(),0);
^
其中, T是类型变量:
T扩展已在类 NodeGroupService中声明的NodeInterface