I have a SimpleIntegerProperty
which should be able to store null
. However, this is not possible, as written in the JavaDoc of IntegerProperty:
Note: setting or binding this property to a
null
value will set the property to "0.0". SeesetValue(java.lang.Number)
.
This also applies to other properties, such as LongProperty
, FloatProperty
, DoubleProperty
, and BooleanProperty
(but not to StringProperty
, which allows null
!). Why is this the case? Is there a workaround to store null
in these properties?
IntegerProperty
,DoubleProperty
, etc, are intended as exactly that: observable wrappers for primitive types. SoIntegerProperty
is intended to wrap anint
, which of course cannot take on anull
value. For convenience,IntegerProperty
implementsProperty<Number>
, so it inherits thesetValue(Number)
method; however it is not intended to be used to set the value tonull
(and as you observed, is documented to set the value to a default of0
). If you want an observable that can take onnull
, useObjectProperty<Integer>
. – Memento