Returns an ObservableValue that holds this value and is updated only when condition holds true.
Returns an ObservableValue that holds this value and is updated only when condition holds true.
The returned ObservableValue only observes this value when condition holds true. This allows this ObservableValue and the conditional ObservableValue to be garbage collected if neither is otherwise strongly referenced when condition holds false. This is in contrast to the general behavior of bindings, where the binding is only eligible for garbage collection when not observed itself.
A condition holding null is treated as holding false.
For example:
val condition = BooleanProperty(true)
val longLivedProperty = StringProperty("A")
val whenProperty = longLivedProperty.when(condition)
// observe whenProperty, which will in turn observe longLivedProperty
whenProperty.onChange((_, old, current) => println(s"whenProperty change : $old -> $current"));
longLivedProperty.value = "B" // "B" is printed
condition.value = false
// After condition becomes false, whenProperty stops observing longLivedProperty; condition
// and whenProperty may now be eligible for GC despite being observed by the ChangeListener
longLivedProperty.value = "C" // nothing is printed
longLivedProperty.value = "D" // nothing is printed
condition.value = true // longLivedProperty is observed again, and "D" is printed
Value parameters
condition
a boolean ObservableValue, cannot be null
Attributes
Returns
an ObservableValue that holds this value whenever the given condition evaluates to true, otherwise holds the last seen value; never returns null