I have this code :
private MyClass myMethod(HashMap<MyEnum, String> preferences, String type){
// stuff
preferences.put(MyEnum.enum, type);
MyClass myClass = ExtractMyClass(preferences);
return myClass;
}
I call this method here :
public List<MyClass> myBigClass(){
List<MyClass> myList = new ArrayList<>();
//do a lot of stuff
Map<MyEnum, String> preferences = new HashMap<>();
preferences.put(MyEnum.enum, "value0");
myList.add(myMethod(preferences, "value1")); //first call
myList.add(myMethod(preferences, "value2")); //second call
myList.add(myMethod(preferences, "value3")); //third call
return myList;
}
In the first call, preferences
contains only value0
In the second call, it contains value0
" and value1
And in the third call, it has value0
, value1
and value2
I want that, for the three calls, preferences
should have only value0
Why does the other values stay there, even though it was added inside a method ?