尝试使用-Xlint开关后,我收到2个警告.我该如何解决这些警告?
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
Run Code Online (Sandbox Code Playgroud)
原始类型是可以具有类型参数但尚未开启的类型.例如Map(和HashMap)可以分别具有类型参数K以及V键和值的类型.
因此,您可以指定a Map<Integer,String>来指示地图包含Integer对象作为键并将它们映射到String对象.
如果您只是使用,Map那么您不提供该信息.原始类型主要用于向后兼容,并且没有理由在新代码中使用它们.
解决方案:为您提供合适的类型Map.根据你的代码时,V会UniformDistribution和K会的类型yKey和xKey.