PDA

View Full Version : [java] lista static dis tringhe


prazision
29-12-2010, 11:26
in una classe Java ho una lista di stringhe

una volta inizializzata non cambia

io l'ho definita static e la inizializzo in un blocco static in modo che rimanga come lista di classe

è corretta come cosa?

grazie

tuccio`
29-12-2010, 13:11
se ha senso che non sia vincolata alle istanze e che tutti gli oggetti accedano alla stessa lista sì

se invece per "una volta inizializzata non cambia" intendi che non deve essere modificabile (e eventualmente anche non statica) quello che ti serve è questo metodo: http://download.oracle.com/javase/1.4.2/docs/api/java/util/Collections.html#unmodifiableList%28java.util.List%29

prazision
29-12-2010, 14:35
public class Cucina{

private static List<Pentole> pentoleLista;

static{
pentoleLista= new LinkedList<Pentole>();
}

public Cucina(){
...
}
...
}



visto che la lista di pentole non cambia, ho pensato fosse inutile istanziarla ogni volta

è corretto?

Grazie

Hardware Upgrade Forum Database Error
Database Error Database error
The Hardware Upgrade Forum database has encountered a problem.

Please try the following:
  • Load the page again by clicking the Refresh button in your web browser.
  • Open the www.hwupgrade.it home page, then try to open another page.
  • Click the Back button to try another link.
The www.hwupgrade.it forum technical staff have been notified of the error, though you may contact them if the problem persists.
 
We apologise for any inconvenience.