I found good explanation here.
When intProperty.set(7168) is called, it fires an invalidation event
to otherProperty. Upon receiving this invalidation event,
otherProperty simply makes a note of the fact that its value is no
longer valid. It does not immediately perform a recalculation of its
value by querying intProperty for its value. The recalculation is
performed later when otherProperty.get() is called. Imagine if instead
of calling intProperty.set() only once as in the above code we call
intProperty.set() multiple times; otherProperty still recalculates its
value only once.
As after testing I found this example.
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
public class InvalidMean{
public static void main(String[] args){
IntegerProperty num1 = new SimpleIntegerProperty(15);
IntegerProperty num2 = new SimpleIntegerProperty(10);
// num2.bind(num1);
// num1.set(56);
System.out.println(num2);
}
}
Run this code You will get this output:
IntegerProperty [value: 10]
Now remove the comment from commented lines. and you will get this output.
IntegerProperty [bound, invalid]
num2
's value become invalid because new value arrived but not updated yet. As JavaFX Doc describe it just because of lazy evaluation.
The JavaFX binding and property implementations all support lazy
evaluation, which means that when a change occurs, the value is not
immediately recomputed. Recomputation happens later, if and when the
value is subsequently requested.
If you want the value should be valid call num2.getValue();
or num2.get();
Before System.out.println(num2);
you will see property will be valid then.
Note: In the above example num2.bind(num1);
and num1.set(56);
both will make invalid the value of num2
because bind already changing the value of num2
and set()
also trying to change the value.