I am adding/editing objects that are values in a hashmap-- with different keys.
However, editing one object in the hashmap seems to edit them all(?)
What am I doing wrong here?
First, my (poorly named) hashmap class:
import java.util.HashMap;
public class hashmap {
static HashMap<Integer, exObj> hm;
hashmap(){
hm = new HashMap<Integer, exObj>();
}
public void createVal(){
for (int i = 0; i<10; i++){
hm.put(i, new exObj(i));
}
hm.get(2).setValue();
}
public void printVal(){
for (int i = 0; i<10; i++){
System.out.println(hm.get(i).getValue());
}
}
public static void main(String args[]){
hashmap hmap = new hashmap();
hmap.createVal();
hmap.printVal();
}
}
Second, my simple exObj Class:
public class exObj {
private static int value;
exObj(int i){
value = i;
}
public void setValue(){
value = value + 1;
}
public int getValue(){
return value;
}
}
returns output:
10
10
10
10
10
10
10
10
10
10