As you know an ObservableValue
in java can generate two types of events: Invalidation
and Change
. I don't know what's the difference between them?
When we should use Invalidation or Change Listener?
As you know an ObservableValue
in java can generate two types of events: Invalidation
and Change
. I don't know what's the difference between them?
When we should use Invalidation or Change Listener?
As per documentation:
An
ObservableValue
generates two types of events: change events and invalidation events. A change event indicates that the value has changed. An invalidation event is generated, if the current value is not valid anymore.This distinction becomes important, if theObservableValue
supports lazy evaluation, because for a lazily evaluated value one does not know if an invalid value really has changed until it is recomputed. For this reason, generating change events requires eager evaluation while invalidation events can be generated for eager and lazy implementations.
ChangeListener enforces eager computation even when the observable value supports lazy evaluation.
If you want to find the change that happened in observed property, you use a change listener. Where as the InvalidationListener only helps us know some change has happened, if you want to know the difference between old and new values, you have to compute that yourself or simply use change listener.