0

I have noticed that Observable.notifyObservers notifies the latest "subscribers" before the earlier ones, is there a reason why it notifies from the end of the array?

 public void notifyObservers(Object arg) {
    Object[] arrLocal;
    synchronized (this) {
 
        if (!changed)
            return;
        arrLocal = obs.toArray();
        clearChanged();
    }

    for (int i = arrLocal.length-1; i>=0; i--)
        ((Observer)arrLocal[i]).update(this, arg);
}
Kassab
  • 82
  • 1
  • 7
  • 3
    It's been that way for at least 16 years, which is far back as the openjdk source code goes. That being the case, all you're going to get is speculation. There isn't necessarily any good reason. – Michael Feb 07 '23 at 15:52
  • 3
    The [documentation](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Observable.html) states: _The order in which notifications will be delivered is unspecified._ And note that since Java 9 you should no longer be using `Observable` / `Observer` - see https://stackoverflow.com/questions/46380073/observer-is-deprecated-in-java-9-what-should-we-use-instead-of-it for more information. – Thomas Kläger Feb 07 '23 at 15:57

0 Answers0