Class TypedKey<T>

java.lang.Object
growthbook.sdk.java.model.TypedKey<T>
Type Parameters:
T - the value type the feature evaluates to
All Implemented Interfaces:
FeatureKey<T>

public final class TypedKey<T> extends Object implements FeatureKey<T>
Default immutable implementation of FeatureKey.

Declare feature keys as constants and reference them wherever a feature is evaluated:


 public final class Features {
     public static final TypedKey<Boolean> NEW_HOME  = TypedKey.ofBoolean("new-home");
     public static final TypedKey<String>  THEME     = TypedKey.ofString("theme");
     public static final TypedKey<Integer> MAX_ITEMS = TypedKey.ofInteger("max-items");
     public static final TypedKey<MyConfig> CONFIG   = TypedKey.of("my-config", MyConfig.class);
     private Features() {}
 }
 
  • Method Details

    • of

      public static <T> TypedKey<T> of(String key, Class<T> valueType)
      Creates a typed key for an arbitrary Gson-deserializable value type.
      Type Parameters:
      T - the value type
      Parameters:
      key - the feature identifier
      valueType - the value type class, e.g. MyConfig.class
      Returns:
      a new typed key
    • ofBoolean

      public static TypedKey<Boolean> ofBoolean(String key)
      Creates a typed key for a boolean feature.
      Parameters:
      key - the feature identifier
      Returns:
      a new typed key
    • ofString

      public static TypedKey<String> ofString(String key)
      Creates a typed key for a string feature.
      Parameters:
      key - the feature identifier
      Returns:
      a new typed key
    • ofInteger

      public static TypedKey<Integer> ofInteger(String key)
      Creates a typed key for an integer feature.
      Parameters:
      key - the feature identifier
      Returns:
      a new typed key
    • ofDouble

      public static TypedKey<Double> ofDouble(String key)
      Creates a typed key for a double feature.
      Parameters:
      key - the feature identifier
      Returns:
      a new typed key
    • ofFloat

      public static TypedKey<Float> ofFloat(String key)
      Creates a typed key for a float feature.
      Parameters:
      key - the feature identifier
      Returns:
      a new typed key
    • getKey

      public String getKey()
      Description copied from interface: FeatureKey
      The feature identifier as configured in GrowthBook, e.g. "new-home".
      Specified by:
      getKey in interface FeatureKey<T>
      Returns:
      the raw feature key
    • getValueType

      public Class<T> getValueType()
      Description copied from interface: FeatureKey
      The Gson-deserializable class of the feature value, e.g. Boolean.class.
      Specified by:
      getValueType in interface FeatureKey<T>
      Returns:
      the value type
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object