JavaFX2.2:如何将SimpleBoleAnProperty值设置为null?

JavaFX2.2:如何将SimpleBoleAnProperty值设置为null?,java,javafx-2,Java,Javafx 2,如果我这样做: BooleanProperty b = new SimpleBooleanProperty(); b.setValue(null); System.out.println(b.getValue()); 我接收输出: false 如何将SimpleBoleanProperty值设置为null?将simpleboleanproperty设置为null(BooleanProperty b=null;)是个坏主意,因为我将使用绑定 我找到了方法: ObjectProperty<

如果我这样做:

BooleanProperty b = new SimpleBooleanProperty();
b.setValue(null);
System.out.println(b.getValue());
我接收输出:

false
如何将
SimpleBoleanProperty
值设置为
null
?将
simpleboleanproperty
设置为
null
BooleanProperty b=null;
)是个坏主意,因为我将使用绑定

我找到了方法:

ObjectProperty<Boolean> b = new SimpleObjectProperty<Boolean>(null);
System.out.println(b.getValue());
ObjectProperty b=新的SimpleObjectProperty(null);
System.out.println(b.getValue());
很好


我不能回答我的问题,所以我把它放在这里,对不起。

我认为没有办法将值设置为
null
。查看
BooleanProperty#setValue
实现

public void setValue(Boolean paramBoolean)
{
    set(paramBoolean == null ? false : paramBoolean.booleanValue());
}

这正是您看到的行为。

SimpleBoleanProperty是一个围绕
布尔值的包装器(原语)-空值自动设置为默认(假)值

如果要允许
null
值,可以使用
ObjectProperty b=newsimpleobjectproperty()。缺点是会丢失默认的布尔绑定


或者,您可以创建一个覆盖现有setValue实现的自定义类,但这可能有点复杂,因为它依赖于
set(boolean)
方法,该方法显然不能接受
null

为什么要将
布尔值设置为
null
?@mre我需要3种状态:真、假、未确定。我想将
Boolean
值设置为
null
,而不是
Boolean