On Mon, 17 Feb 2025 21:11:01 GMT, Michael Strauß <mstra...@openjdk.org> wrote:
> Do you have any ideas on how to make `ChangeListener` also work sensibly for > `ListProperty`, `SetProperty`, and `MapProperty`? Well, I don't think it is reasonable or desired to have correct old values for these, as it would basically mean we'd need to clone the collection involved to give you a correct old value. The purpose of the old value here would be so you could do a diff and see what's changed, but these properties have their own callbacks for exactly that purpose. IMHO, it was a mistake to base these on properties; at most they should have provided invalidation + their custom diff-style callback. A big problem with `ListProperty` (versus just exposing say `ObservableList`) is that there are now two ways you can change the list. I can either replace it completely by doing `listProperty.set(list)` or I can do it with `listProperty.get().setAll(list)`. In the first case, a sensible old value is possible (you're using the `ListProperty` as a property, replacing its value with a new value). In the 2nd case however, there is no 2nd list involved, and both the old and new value can only refer to the same list. Cloning here would be too unreasonable to even consider. So, if it becomes a problem, I'd be in favor of marking the change listener methods on these as deprecated, as they're only useful to get a slightly more convenient form of invalidation listener where you don't have to call "get" but can just use the `newValue` parameter provided directly (ignoring the `oldValue` as it will contain nonsense). We could even still provide `subscribe(Consumer)` but implement it via invalidation + get for these properties. ------------- PR Comment: https://git.openjdk.org/jfx/pull/1081#issuecomment-2664164237