RFR: JDK-8304439: Subscription based listeners [v2]

Michael Strauß mstrauss at openjdk.org
Mon Apr 10 19:21:17 UTC 2023


On Mon, 27 Mar 2023 14:36:45 GMT, John Hendrikx <jhendrikx at openjdk.org> wrote:

>> Makes `Subscription` public (removing some of its methods that are unnecessary), and adds methods that can provide `Subscription`s in `ObservableValue`.
>
> John Hendrikx has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Move Subscription method for invalidations to Observable
>   
>   - moved Subscription class to the Observable package

modules/javafx.base/src/main/java/javafx/beans/Observable.java line 107:

> 105:      * @since 21
> 106:      */
> 107:     default Subscription invalidations(Runnable subscriber) {

I think re-using `InvalidationListener` may fit better into the existing JavaFX API:

interface Observable {
    Subscription subscribe(InvalidationListener);
}


The method can then be overloaded for `ChangeListener`, `ListChangeListener`, `SetChangeListener`, and `MapChangeListener` as well. Doing so allows users to use the same functional interfaces they've used before with the `addListener`/`removeListener` APIs.

As an added bonus, we don't need to allocate a wrapper for the listeners.

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/1069#discussion_r1162007648


More information about the openjfx-dev mailing list