通常,在eclipse中,我可以运行代码而不会出现任何编译错误。然而,在使用ant文件时,我遇到了error: type argument Map is not within bounds of type-variable Type。我的ant文件有什么问题?
代码我认为是错误的;
[javac] class StratI implements Strat<Map> {
[javac] ^
[javac] where T is a type-variable:
[javac] T extends Map<?,?> declared in interface Strat
[javac] 1 errorAnt - javac部分;
<target name="compile" depends="init">
<javac compiler="javac1.7"
destdir="${build.dir}/classes"
source="1.7"
target="1.7"
includeantruntime="false"
encoding="ISO-8859-1">
<src path="${src.dir}" />
<classpath refid="classpath" />
</javac>
</target>注意:我已经在谷歌上搜索了这个错误。我没有看到任何能说明真正原因并说明如何解决它的来源。
发布于 2014-08-25 21:40:41
Map是一个raw-type,如错误中所述,它是is not within bounds of type-variable Type,即T extends Map<?,?>。尽管你正在扩展一个“随心所欲”的映射,但它仍然是一个原始类型的规范。
您应该在以下位置更改StratI接口实现的声明:
class StratI implements Strat<Map<?,?>>或者因为你在扩展
class StratI implements Strat<HashMap<?,?>>或者因为它是一种实现
class StratI implements Strat<HashMap<Integer, String>>编辑
Eclipse不会将其显示为错误的事实是,Eclipse不会为未参数化的原始类型显示编译错误。它会显示一条警告:
public interface myIn<T extends Map<?,?>>{
void foo();
}
public class myClass implements myIn<Map>{
@Override
public void foo() {}
}Eclipse将在Map下面加上警告:
Map是一种原始类型。对泛型类型Map<K,V>的引用应参数化为
https://stackoverflow.com/questions/25486800
复制相似问题