开发者

Alternative to the approach 'Adding items to Enumerator '?

I have my application design where I have a set of cities and I want to add them in a Enum. Mostly for a year or so those are the cities I will need to work on. However the city list will grow sooner or later, which will then require to add elements to enum.

From what I understand there is no 'nice' way to add elements to an Enum, there seen to be cert开发者_如何学Goain hacks but for now it looks as if it is better to steer away from them.

So what should be my approach in this case? I could use plain String but I would want something better.


Why not just use a Set for this. And use the set's iterator to enumerate over all the cities.

Enum is not designed to be dynamically updated. its conceptually static in nature


you could probably use a flyweight approach (if my memory serves me correctly) whereas you have a class with a private constructor (similar to Singleton) and this class will manage all the instances of itself -- there will be one single instance in the system for each city, all managed by the class itself, and as such you can use == instead of equals() just as you would with enum.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜