[8u] API Request: RT-25613, ObservableValue should have a hasListener(listener) method

Martin Sladecek martin.sladecek at oracle.com
Wed Jan 22 04:15:22 PST 2014

On 01/22/2014 12:30 PM, Richard Bair wrote:
>>> The default implementation (for Observable) would look like this:
>>> public default void ensureListener(InvalidationListener listener) {
>>>     removeListener(listener);
>>>     addListener(listener);
>>> }
>>> subclasses might do something more effective. The same would apply to
>>> ObservableValue and ChangeListener and Observable[List|Set|Map] and
>>> [List|Set|Map]ChangeListener.
>> Well this would destroy the order! I expect listeners to be called in
>> the correct order not?
> That’s a good point :-(
>> Why doing a remove and not simply check if the
>> listener has already been added?
> Because there is no way to check, except in the implementation. From the Observable interface level, there is no way to a) force all implementations of the interface to implement the method correctly (without breaking source compatibility anyway), or b) to provide a reasonable default implementation.
> Maybe this is one of those things we can’t fix on the Observable interface and just have to provide implementations of on our concrete properties.
Unfortunately, this is not possible (without requiring users to cast). 
Most properties are exposed in API through ReadOnly*Property and 
*Property classes, which are abstract and do not have access to the 
listeners. Same with FX collections, an interface is returned from the 
API, not the base class.


More information about the openjfx-dev mailing list