Search code examples
javafxreactfx

ReactFX: can't build EventStream from DoubleProperty


I'm trying to make an EventStream from a DoubleProperty in ReactFX (I've tried both 2.0M5 and 1.4.1 stable). I constantly get this error from IntelliJ:

Incompatible Type Error

I've tried using the sample code from the wiki:

Circle streamCircle = new Circle();
EventStream<Double> widthValues = EventStreams.nonNullValuesOf(streamCircle.radiusProperty());

...and I get the same error.

What am I doing wrong?


Solution

  • DoubleProperty, IntegerProperty and similar properties implement ObservableValue<Number>, not ObservableValue<Double>, ObservableValue<Integer>, ect.

    You could use asObject for conversion to such a type:

    EventStream<Double> widthValues = EventStreams.nonNullValuesOf(streamCircle.radiusProperty().asObject());
    

    But if I correctly understand what nonNullValuesOf is supposed to do, you should replace this by EventStreams.valuesOf, since a DoubleProperty never contains null as value.