我有一个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 [bound,invalid]
答案 0 :(得分:4)
DoubleProperty
是一个包装类。获得实际价值
System.out.println(pctDiscount.getValue());
或
System.out.println(pctDiscount.get());