|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Junior Member
Iscritto dal: Jan 2006
Città: Agrigento
Messaggi: 18
|
[java] Istanze di una classe
Salve a tutti,
qualcuno sa come faccio a run-tim quanti oggetti di una determinata classe sono stati creati ? Es: --------- public class miaClasse { } ---------- public class Test { public static void main(String[] args) { // in questo punto, ad esempio, come faccio a sapere quanti oggetti di tipo // miaClasse sono stati creati ? } } ------------------- Grazie |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Oct 2002
Città: Roma
Messaggi: 1502
|
puoi mettere nella tua classe un campo contatore static che viene incrementato all'interno del costruttore della classe e che essendo static può essere acceduto ovunque con la sintassi miaClasse.contatore
__________________
Sun Certified Java Programmer EUCIP Core Level Certified European Certification of Informatics Professionals |
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Oct 2004
Città: Bologna
Messaggi: 50
|
Dentro a MiaClasse:
Codice:
private static int numeroIstanze;
// costruttore di MiaClasse
public MiaClasse( /*...*/ ) {
// ...
numeroIstanze++;
// ...
}
public static int getNumeroIstanze() {
return numeroIstanze;
}
__________________
And the salad is frightful! I have an important message to deliver to all the cute people all over the world. If you're out there and you're cute, maybe you're beautiful. I just want to tell you something: there's more of us ugly mother-fuckers than you are, hey-y, so watch out. |
|
|
|
|
|
#4 | |
|
Member
Iscritto dal: Oct 2004
Città: Bologna
Messaggi: 50
|
Quote:
__________________
And the salad is frightful! I have an important message to deliver to all the cute people all over the world. If you're out there and you're cute, maybe you're beautiful. I just want to tell you something: there's more of us ugly mother-fuckers than you are, hey-y, so watch out. |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 21:25.



















