3

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)

ESipalis
  • 381
  • 4
  • 17

1 Answers1

6

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>.)

James_D
  • 201,275
  • 16
  • 291
  • 322