Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why IntegerProperty implements Property<Number> and not Property<Integer>?

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:

enter image description here

like image 493
Paolo Fulgoni Avatar asked Jan 08 '16 10:01

Paolo Fulgoni


People also ask

What is 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.

What is SimpleIntegerProperty in JavaFX?

Class SimpleIntegerPropertyThis class provides a full implementation of a Property wrapping a int value. Since: JavaFX 2.0 See Also: IntegerPropertyBase.


1 Answers

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.

like image 117
Modus Tollens Avatar answered Sep 28 '22 09:09

Modus Tollens