Qual é a melhor forma de inicializar campos: no construtor ou na declaração?
Exemplo:
private String element, indent;
private List declarations;
private List attributes;
public XMLFormatter() {
this.element = "default";
this.indent = " ";
declarations = new LinkedList();
attributes = new LinkedList();
}
Ou…
private String element = "default", indent = " ";
private List declarations = new LinkedList();
private List attributes = new LinkedList();;
public XMLFormatter() {
// desnecessário
}
Qual a diferença?