I am asking because it seems to be a bit inconvenient when implementing ChangeListeners.
slider.valueProperty().addListener((property, oldValue, newValue) -> message.setFont(new Font(newValue)));
does not work. I invite you find out the reason from the error message:
error: no suitable method found for addListener((property,[...]lue)))
slider.valueProperty().addListener((property, oldValue, newValue)
method Observable.addListener(InvalidationListener) is not applicable
(argument mismatch; incompatible parameter types in lambda expression)
method ObservableValue.addListener(ChangeListener<? super Number>) is not applicable
(argument mismatch; cannot type-check lambda expression with inferred parameter types
inferred types: ObservableValue<? extends Number>,Number,Number)
That's actually bogus. newValue is inferred to be Number, and Number doesn't auto-unbox. This works:
slider.valueProperty().addListener((property, oldValue, newValue) -> message.setFont(new Font(newValue.doubleValue())));
So, that's all rather obscure. What was gained by having DoubleProperty implement Property<Number> and not Property<Double>?
This is the way it was done in previous version of FX to simplify the FX code and avoid tons of duplicated code. We've tried to fix this, but it was too late, as the cost of backward incompatibility was too hight.
You can however use conversion methods to achieve this. Like this: