JavaFX SimpleObjectProperty<T> vs SimpleTProperty

坚强是说给别人听的谎言 提交于 2019-12-12 17:24:00

问题


What's the difference between using

SimpleStringProperty vs SimpleObjectProperty < String > or

SimpleIntegerProperty vs SimpleObjectProperty< Integer >

Besides returning wrappers and not primitive types?(It can be auto casted anyways)


回答1:


The API adds additional functionality for the specific types. So ObjectProperty really just defines the API for "being a property" and can only define functionality common to all possible types. On the other hand, StringProperty defines (via its superclass StringExpression) methods such as concat(...) which returns another ObservableValue<String> which is the current value concatenated with the provided value. Similarly, IntegerProperty defines numeric-specific functionality such as add, divide, etc etc.

So the specific types just add extra functionality to the more general type that is specific to those types. It is just the standard use of inheritance.

(Note though, that IntegerProperty does not implement Property<Integer>, it implements Property<Number>.)



来源:https://stackoverflow.com/questions/41638183/javafx-simpleobjectpropertyt-vs-simpletproperty

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