Paul Clapham wrote:...the listener might be called superfluously.
I should add that I'd be concerned that "superfluously" here might, instead, have been "catastrophically."
For instance, if a listener is created in reliance on the availability of a resource that later becomes unavailable, a naive programmer might think they can avoid untimely attempts to use the resource by "destroying" the listener. Something like this:
The mistake, of course, would be to assume that Line 5 destroyed the listener; it doesn't, as the eventGenerator still holds a reference to it (even if it's a weak reference, if the GC hasn't gotten around to it). But,
this works in hoary old VB6, because Line 5
does destroy the listener object and the language itself doesn't send events to destroyed objects.
I would certainly grant that the above would be awful practice in
Java and is not much of a case against explicit removal of listeners (since "list=null" might as well be "eventGenerator.removeListener(list)"), but what if the above fragment were in a method such that list were created locally? Again, a naive Java programmer might assume that an instance with a reference to it held in "list" was destroyed when list went out of scope. Again, that's not what happens. But, it means a programmer might not even have anything like Line 5, and could still close a resource passed to the listener (maybe outside the method that had created the listener).
All in all, it seems like something the language
could have, with no backwards compatibility problems, and lots of useful future applications.