The Property
interface added by JavaFX has a type parameter T
, which is the type of the value wrapped by the property.
Among the implementations of the Property
interface, there are some for numbers: IntegerProperty
, FloatProperty
, etc. All these classes implement Property<Number>
.
Let's take IntegerProperty
for example. What is the reason why it implements Property<Number>
and not Property<Integer>
as I would have expected?
Here is an UML diagram which clarify the hierarchy of IntegerProperty
:
integerProperty(Property<Integer> property) Returns a IntegerProperty that wraps a Property and is bidirectionally bound to it. void. setValue(Number v) Set the wrapped value.
Class SimpleIntegerPropertyThis class provides a full implementation of a Property wrapping a int value. Since: JavaFX 2.0 See Also: IntegerPropertyBase.
As mentioned in the comments section of a Java bug report (DoubleProperty has unexpected generics type),
This design is intended. It keeps the number of required methods significantly smaller.
In this answer's comments, James_D made me aware of a later bug report adressing that issue, ChangeListener cannot be added to SimpleIntegerProperty). The comment
We decided not to change the generics of primitive types properties (from Number to specific type) due to backward-compatibility issues. However, it means this issue cannot be fixed.
suggests that the team considered changing the design, but it was too late.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With