09. maj 2000 - 16:21Der er
3 kommentarer og 1 løsning
Undersøge hvilke instanser man har oprettet.
Findes der en måde hvorpå man kan undersøge hvilke instanser man har oprettet af en bestemt klasse? De forskellige instanser (som får mere eller mindre tilfældige navne) skal kunne kalde en metode.
Bjarne: If you have an static int counter in your class, and you type in constructors body counter++, any time you make a new object you can have the amount of all of them. Jose.
Thanks.. But that wasn't quite what I was trying to do. I was looking for a way to get a list of the names of the instance variables created from a certain class (eg. in an array). However, I think I've worked my way around the problem - but if anyone have the golden answer, please reply! :)
Sorry, i didn´t get the point... but if you make a Vector in your class (or an array of the objects of your class), you can allways write in the constructors body: nameOfTheVector.add(this); So, anytime you make an instance, you can save it in the vector or array, Sounds it better? Jose.
Actually I was looking for something else.. but your sollution will work just fine, so I'll give you your points anyway.. Thanks :)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.