在尝试使用-Xlint开关后,我收到了两个警告。如何解决这些警告?
test:quadrantRDBTemplate mymac$ javac -Xlint:unchecked -cp mysql-connector-java-5.0.jar:iucbrf.jar *.java
QuadrantSystemRDB.java:271: warning: [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.HashMap
argMap.put(xKey, new UniformDistribution(-1, 1));
^
QuadrantSystemRDB.java:272: warning: [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.HashMap
argMap.put(yKey, new UniformDistribution(-1, 1));
^
2 warnings发布于 2011-02-25 15:54:44
原始类型是一种可以有类型参数的类型,但还没有开始。例如,对于键和值的类型,Map (和HashMap)可以分别具有类型参数K和V。
因此,您可以指定一个Map<Integer,String>来指示映射包含Integer对象作为键,并将它们映射到String对象。
如果您只使用Map,那么您就不需要提供这些信息。原始类型的存在主要是为了向后兼容,没有理由在新代码中使用它们。
解决方案:为Map提供适当的类型。根据您的代码,V将是UniformDistribution,K将是yKey和xKey的类型。
发布于 2011-02-25 15:55:17
你应该使用泛型!!假设您的xKey类型是String,然后将argMap声明为:
Map<String, UniformDist> argMap = new HashMap<String, UniformDist>()发布于 2011-02-25 15:54:20
对argMap使用泛型。我认为QuadrantSystemRDB来自您的代码。如果不是,您几乎不能做任何事情:)
https://stackoverflow.com/questions/5114843
复制相似问题