Museful
Museful

Reputation: 6959

Create a DoubleBinding with a constant value

In the following, is there a better way to initialize acc?

// . . .
private DoubleBinding acc = new SimpleDoubleProperty(0).add(0);

public void append(ObservableDoubleValue delta){
    // . . .
    acc = acc.add(delta);
}

Upvotes: 2

Views: 210

Answers (1)

Tunaki
Tunaki

Reputation: 137249

You can create a DoubleBinding with the utilities in the Bindings class (createDoubleBinding):

private DoubleBinding acc = Bindings.createDoubleBinding(() -> 0d);

The argument is a function that returns the value of the binding. In this case, and assuming Java 8, the function returns the constant value 0. Do note that this DoubleBinding won't be bound to any Observable.

Upvotes: 2

Related Questions