I know that the use of static
methods should be avoided, so I have a question and I do not know if it is right to implement ArrayList
as static
, it is accessed by several classes and contains data from every program (just want a single list), in this case okay to use static
?
Should the methods of this class (which are manipulating and reading the ArrayList
) also be static
or should I instantiate the object when using it?
A snippet of code:
public class DadosSalvos {
static private ArrayList <Dados> dados = new ArrayList <>();
public static void setDados(ArrayList dados) {
DadosSalvos.dados = dados;
}
public static ArrayList getDados() {
return dados;
}
}