Why are listener lists (e.g. in Java those that use addXxxListener()
and removeXxxListener()
to register and unregister listeners) called lists, and usually implemented as Lists? Wouldn't a Set be a better fit, since in the case of listeners there's
- No matter in which order they get called (although there may well be such needs, but they're special cases; ordinary listener mechanisms make no such guarantees), and
- No need to register the same listener more than once (whether doing that should result in calling the same listener 1 times or N times, or be an error, is another question)
Is it just a matter of tradition? Sets are some kind of lists under the hood anyway. Are there performance differences? Is iterating through a List
faster or slower than iterating through a Set
? Does either take more or less memory? The differences are certainly almost negligible.