This method is considered as Bad Design. If you can find any other solution solve it that way.
Iterate through Instances
Here is a simple Token class. We keep track of all the instances while creating and letter look through all the created instances to check a simple condition and reset that token if it does.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
//A simple Token class public class Token { static List |
In the goHome() method. We compare current token with all the other tokens that were created. And reset the token to its original state.
Storing all the instances would cause memory leakage since those objects will never be disposed of, since the list will still be referencing them. We need to call the kill() method in that instance you no longer need to remove it from the list and thus Garbage Collector can remove it.
Other option could be to create a separate manager class.
Conclusion
With tracking all the instances in a static array list, and as it is stored in Array we can iterate through it. Thank you!<<<Previous
0 Comments