JavaFX: Storing null in a SimpleIntegerProperty

谁说胖子不能爱 提交于 2019-12-05 17:52:48
user7291698

The IntegerProperty.setValue(java.lang.Number) method is specified in the interfaces WriteableIntegerValue and WriteableValue. The JavaDoc of WriteableIntegerValue, states:

Note: this method should accept null without throwing an exception, setting "0" instead.

If you are looking at the code of the IntegerPropertyBase class, you can also see that the value is actually stored as a primitive int (which never can be null). This is also specified in the JavaFX API of SimpleIntegerProperty:

This class provides a full implementation of a Property wrapping a int value.

Solution: You can simply circumvent that by using a SimpleObjectProperty<Integer> instead of a SimpleIntegerProperty, as a SimpleObjectProperty allows null values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!