You cannot pass information to a constructor of a enum element. You cannot call the constructor from outside the enum class. You can however pass information to methods of an enum element (officially called a constant). The Java™ Tutorials example shows weights being passed to methods of a Planet enum, which calculate the weight on different planets.
I am not convinced you have a factory there, but I may have forgotten my design patterns.
I am sure you can have mutable fields in an enum constant, but I don't think that is the intent behind enums; they are supposed to be constant so they should really not change their state. You appear to have the List of Teams; why don't you use that? You appear already to have methods which amend the List. Why not add methods to find a particular Team and then you can change its state.
Campbell Ritchie wrote:
Try this as an alternative to the method you wrote.Beware: unmodifiable does not mean immutable. It means read‑only. If you alter the List in its original location, or it you alter the state of any of the Teams in the List, those changes will be reflected in the unmodifiable copy.
Campbell Ritchie wrote:
You can simplify that method:-Look up the ArrayList(Collection) constructor.
If the Teams which are elements of that List are mutable, they remain mutable and changed state in one location will be visible in all other locations where that Team object is to be found.
Not sure just at the moment how to make a Team accessible to the enum element. But does the enum element require access to the Teams? Doesn't the menu require that access?
Kendall Ponder wrote:
Campbell Ritchie wrote:
You can simplify that method:-Look up the ArrayList(Collection) constructor.
Thanks! That simplifies things.
It's a tiny ad only because the water is so cold.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|