Why are listener lists Lists?

Posted by Joonas Pulakka on Stack Overflow See other posts from Stack Overflow or by Joonas Pulakka
Published on 2010-05-30T10:39:08Z Indexed on 2010/05/30 10:42 UTC
Read the original article Hit count: 626

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about java

Related posts about list