Interface FlagValueChangeListener

  • public interface FlagValueChangeListener
    An event listener that is notified when a feature flag's value has changed for a specific evaluation context.

    Use this in conjunction with FlagTracker.addFlagValueChangeListener(String, com.launchdarkly.sdk.LDContext, FlagValueChangeListener) if you want the client to re-evaluate a flag for a specific evaluation context whenever the flag's configuration has changed, and notify you only if the new value is different from the old value. The listener will not be notified if the flag's configuration is changed in some way that does not affect its value for that context.

         String flagKey = "my-important-flag";
         LDContext contextForFlagEvaluation = LDContext.create("context-key-for-global-flag-state");
         FlagValueChangeListener listenForNewValue = event -> {
             if (event.getKey().equals(flagKey)) {
             contextForFlagEvaluation, listenForNewValue);
    In the above example, the value provided in event.getNewValue() is the result of calling client.jsonValueVariation(flagKey, contextForFlagEvaluation, LDValue.ofNull()) after the flag has changed.
    See Also:
    FlagChangeListener, FlagTracker.addFlagValueChangeListener(String, com.launchdarkly.sdk.LDContext, FlagValueChangeListener)
    • Method Detail

      • onFlagValueChange

        void onFlagValueChange​(FlagValueChangeEvent event)
        The SDK calls this method when a feature flag's value has changed with regard to the specified evaluation context.
        event - the event parameters