RFR: 8264770: BidirectionalBinding should use InvalidationListener to prevent boxing [v2]

Michael Strauß mstrauss at openjdk.java.net
Fri May 14 22:30:16 UTC 2021


> The internal BidirectionalBinding class implements bidirectional bindings for JavaFX properties. The design intent of this class is to provide specializations for primitive value types to prevent boxing conversions (cf. specializations of the Property class with a similar design intent).
> 
> However, the primitive BidirectionalBinding implementations do not meet the design goal of preventing boxing conversions, because they implement ChangeListener.
> 
> ChangeListener is a generic SAM interface, which makes it impossibe to invoke an implementation of ChangeListener::changed with a primitive value (i.e. any primitive value will be auto-boxed).
> 
> The boxing conversion happens, as with all ChangeListeners, at the invocation site (for example, in ExpressionHelper). Since the boxing conversion has already happened by the time any of the BidirectionalBinding implementations is invoked, there's no point in using primitive specializations of BidirectionalBinding after the fact.
> 
> This issue can be solved by having BidirectionalBinding implement InvalidationListener instead, which by itself does not incur a boxing conversion. Because bidirectional bindings are eagerly evaluated, the observable behavior remains the same.
> 
> I've filed a bug report with the same title.

Michael Strauß has updated the pull request incrementally with one additional commit since the last revision:

  added missing oldValue assignments

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

Changes:
  - all: https://git.openjdk.java.net/jfx/pull/454/files
  - new: https://git.openjdk.java.net/jfx/pull/454/files/1142087a..538b9b38

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jfx&pr=454&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=jfx&pr=454&range=00-01

  Stats: 2 lines in 1 file changed: 2 ins; 0 del; 0 mod
  Patch: https://git.openjdk.java.net/jfx/pull/454.diff
  Fetch: git fetch https://git.openjdk.java.net/jfx pull/454/head:pull/454

PR: https://git.openjdk.java.net/jfx/pull/454


More information about the openjfx-dev mailing list