eclipse 对泛型类型 Map<K,C> 的引用应该被参数化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4068423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
References to generic type Map<K,C> should be parameterized
提问by Qwerty
In an abstract class is the following abstract method definition:
在抽象类中是以下抽象方法定义:
public abstract Map<String, String> aMethod(aType type);
I am unable to prevent this warning in Eclipse:
我无法在 Eclipse 中阻止此警告:
References to generic type Map should be parameterized
对泛型类型 Map 的引用应该被参数化
I've been searching around and can't seem to work this out. I've found others experiencing the same error, but in their cases it seemed to make sense. In mine I can't see the logic.
我一直在四处寻找,似乎无法解决这个问题。我发现其他人遇到了同样的错误,但在他们的情况下,这似乎是有道理的。在我的我看不到逻辑。
I could suppress warnings, but I'd like to understand what's going wrong before implementing a workaround.
我可以抑制警告,但我想在实施解决方法之前了解出了什么问题。
Thanks.
谢谢。
回答by Bozho
Your Map
is already parameterized, so the warning does not make sense. Try cleaning your project.
你Map
已经参数化了,所以警告没有意义。尝试清理您的项目。
回答by thejh
This warning is propably caused by something like
这个警告可能是由类似的东西引起的
public Map aMethod(aType type);
The difference to this:
与此的区别:
public Map<String, String> aMethod(aType type);
is that the latter creates a Map that you can only put Strings inside, but you can be sure that you always get Strings when requesting a value. The former makes you able to put everything inside it, but you can't be sure what you will get when fetching a value off the Map.
是后者创建了一个只能将字符串放入其中的 Map,但是您可以确保在请求值时始终获取字符串。前者使您能够将所有内容放入其中,但是您无法确定从 Map 中获取值时会得到什么。
回答by aioobe
Are you sure the error is up to date with the file?
您确定错误与文件是最新的吗?
This compiles without a warning:
这在没有警告的情况下编译:
import java.util.Map;
class aType {}
public abstract class Main {
public abstract Map<String, String> aMethod(aType type);
}
This however produces the error you describe:
但是,这会产生您描述的错误:
import java.util.Map;
class aType {}
public abstract class Main {
public abstract Map aMethod(aType type);
}