如何从BigDecimal
创建DoubleBinding
private transient ObjectProperty<BigDecimal> sell;
private ObjectProperty<Operation> operation = new SimpleObjectProperty<>();
private ObjectProperty<BigDecimal> volume = new SimpleObjectProperty<>();
有错误:
sell = Bindings.createDoubleBinding(new Callable<Double>() {
Double volumeDouble = volume.get().doubleValue();
@Override
public Double call() throws Exception {
return (operation.get() == Operation.SELL) ? volumeDouble : 0;
}
}, volume, operation);
答案 0 :(得分:2)
您不能将ObjectBinding<BigDecimal>
强制转换为ObjectProperty<BigDecimal>
,因为在这种情况下使用的绑定类不会扩展ObjectProperty
。您可以将SimpleObjectProperty<BigDecimal>
绑定到ObjectBinding<BigDecimal>
坚韧。
顺便说一句:请注意,代码段中的volumeDouble
字段是在创建绑定时分配的,即使以后修改volume
属性,也不会基于卷进行更新。 / p>
final ObjectProperty<BigDecimal> sell = new SimpleObjectProperty<>();
ObjectBinding<BigDecimal> binding = Bindings.createObjectBinding(new Callable<BigDecimal>() {
@Override
public BigDecimal call() {
return (operation.get() == Operation.SELL) ? volume.get() : BigDecimal.ZERO;
}
}, volume, operation);
sell.bind(binding);