Reputation: 6817
I got 2 warnings after trying to use the -Xlint switch. How can I solve these warnings?
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
Upvotes: 5
Views: 8758
Reputation: 91
Probably, that is because you need to declare a List object, say (e.g.), without omitting '<' and '>':
List<Integer> list = new ArrayList();
I tried to declare object in stack without in NetBeans, and NetBeans compiled my code with no error messages. Maybe, things are different with javac compiler.
Upvotes: 1
Reputation: 24801
You should use generics!! Say your xKey type is String, then declare the argMap as:
Map<String, UniformDist> argMap = new HashMap<String, UniformDist>()
Upvotes: 4
Reputation: 308269
A raw type is a type that could have a type argument, but hasn't got on. For example Map
(and HashMap
) can have type parameters K
and V
for the types of keys and values, respectively.
So you could specify a Map<Integer,String>
to indicate that the map contains Integer
objects as keys and maps them to String
objects.
If you use simply Map
then you don't provide that information. Raw types exist mostly for backwards compatibility and there is no reason to use them in new code.
Solution: provide the appropriate types to your Map
. According to your code, the V
would be UniformDistribution
and K
would be the type of yKey
and xKey
.
Upvotes: 7
Reputation: 47403
Use generics for the argMap
. I suppose the QuadrantSystemRDB
is from your code. If it is not you can hardly do anything:)
Upvotes: 1