The compiler complains about this code:
HashMap userName2ind = new HashMap();
for (int i=0; i<=players.length; i++) {
userName2ind.put(orderedUserNames[i],i+1);
}
It writes "unexpected type" and point on int. If I replace int by String and i+1 by i+"1", the compilation goes OK. What is wrong with in here?
解决方案
It's fine with Integer, but not okay with int - Java generics only work with reference types, basically :(
Try this - although be aware it will box everything:
HashMap userName2ind = new HashMap();
for (int i=0; i<=players.length; i++) {
userName2ind.put(orderedUserNames[i],i+1);
}