0

我正在尝试创建一个绑定BigDecimal属性,该属性是对其他两个属性的计算BigDecimal,如下所示:

val caculatedProperty: ObjectProperty<BigDecimal> = objectBinding<Any, BigDecimal>(sumProperty, discountProperty) { ... }

...就像我对StringPropertyor所做的那样IntegerProperty,否则它会毫无问题地工作。但是,这一次我得到一个类型不匹配:它期望ObjectProperty<BigDecimal>,但接收ObjectBinding<BigDecimal?>

这里有什么问题?我是不是用objectProperty()错了方法?我应该使用其他方法来创建自定义对象的绑定吗?

编辑:

问题是我试图ObjectProperty<BigDecimal>ObjectBinding<BigDecimal>. 就我而言,解决方案是制作原始ObjectProperty<BigDecimal>抽象,并将实现留给继承它的类。

4

1 回答 1

0

All the xBinding functions returns bindings, not properties. If you think about it, how would a calculated property behave if it was writable? Should it write back into the underlying properties perhaps? TornadoFX actually supports these kinds of proxy properties as well, but I suspect that's not what you're after.

Are you wondering why you get ObjectBinding<BigDecimal?> instead of ObjectBinding<BigDecimal>?

The reason is that the underlying property might be null, and if so we might want to return null from the calculated binding as well.

This normally doesn't create an issue, the property is still observable and would carry the correct calculated BigDecimal value.

于 2017-02-07T19:49:10.397 回答