I'm sorry if the question is unnecessary or if the problem is obvious, but I've tried to solve this for several hours and I'm running out of ideas.
public List<Letter> convertToList(char[] array){
List<Letter> result = new ArrayList<>();
for(int i = 0; i < array.length; i++){
result.add(new Letter(array[i]));
}
return result;
}
Here's the code of the Letter class:
public class Letter{
private static char content;
private boolean guessed = false;
public Letter(char content){
this.content = content;
}
public char getContent(){
return this.content;
}
}
The result of running the covertToList() method is a List, which contains different Letter objects, which all have the same content. For example, if I pass in an array a = [T, E, S, T], the function will return a List with different Letter objects, which all have the content "T". I found out that the list is overwritten in every step, so in the first iteration, the List is [T], in the second it's [E, E].
I feel kind of stupid for not seeing the issue. Can someone help?