Why is EventListenerList traversed backwards in fireFooXXX()?

后端 未结 3 1494
梦如初夏
梦如初夏 2021-01-05 15:14

I don\'t understand the rationale of this code, taken from javax.swing.event.EventListenerList docs:

protected void fireFooXXX() {
    // Guaranteed to retur         


        
3条回答
  •  别那么骄傲
    2021-01-05 15:36

    1. Probably performance considerations: backwards iteration is faster because comparison with 0 is a single machine code instruction - lots of former C programmers have that ingrained even though it's rather irrelevant nowadays. Note that there is no guarantee about the order in which listeners will be notified anyway.
    2. Look at the rest of the class - it stores the listeners' types as well to provide type safety.

提交回复
热议问题