Why Java compiler does not like integer as type for values in HashMap?
Posted
by Roman
on Stack Overflow
See other posts from Stack Overflow
or by Roman
Published on 2010-03-24T15:24:31Z
Indexed on
2010/03/24
15:33 UTC
Read the original article
Hit count: 187
The compiler complains about this code:
HashMap<String,int> userName2ind = new HashMap<String,int>();
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?
© Stack Overflow or respective owner