Interface FeatureKey<T>

Type Parameters:
T - the value type the feature evaluates to
All Known Implementing Classes:
TypedKey

public interface FeatureKey<T>
A type-safe reference to a feature flag.

Instead of passing raw string keys such as growthBook.isOn("new-home"), callers declare their feature keys once and reference them through this interface:


 public final class Features {
     public static final FeatureKey<Boolean> NEW_HOME = TypedKey.ofBoolean("new-home");
     public static final FeatureKey<String>  THEME    = TypedKey.ofString("theme");
     private Features() {}
 }

 growthBook.getFeature(Features.NEW_HOME);       // FeatureResult<Boolean>
 growthBook.getBooleanFeature(Features.NEW_HOME);
 

The key carries both the feature identifier and its value type, so a mistyped string key becomes a compile-time error rather than a silent runtime miss.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    The feature identifier as configured in GrowthBook, e.g.
    The Gson-deserializable class of the feature value, e.g.
  • Method Details

    • getKey

      String getKey()
      The feature identifier as configured in GrowthBook, e.g. "new-home".
      Returns:
      the raw feature key
    • getValueType

      Class<T> getValueType()
      The Gson-deserializable class of the feature value, e.g. Boolean.class.
      Returns:
      the value type