0

我有一个 DoubleProperty( price),我希望将第二个 DoubleProperty( discountedPrice) 绑定到price - 25%.

所以我想我会使用该multiply方法,但它似乎没有按预期工作:

DoubleProperty price = new SimpleDoubleProperty();
DoubleProperty pctDiscount = new SimpleDoubleProperty();
pctDiscount.bind(price.multiply(0.75));

price.set(100);

System.out.println(pctDiscount);

我期待程序输出 75 但输出是:

DoubleProperty [绑定,无效]

4

1 回答 1

4

DoubleProperty是一个包装类。获取实际价值

System.out.println(pctDiscount.getValue());

或者

System.out.println(pctDiscount.get());
于 2013-10-06T22:51:53.363 回答