import com.launchdarkly.sdk.LDUser;
import com.launchdarkly.sdk.server.LDClient;
class Test {
public void a() {
LDClient client = new LDClient("sdk-key");
LDUser user = new LDUser.Builder("user-key")
.name("user")
.build();
boolean flagValue = client.boolVariation("flag-key-123abc", user, false);
if (flagValue) {
// Application code to show the feature
} else {
// The code to run if the feature is off
}
}
}
After:
import com.launchdarkly.sdk.LDUser;
import com.launchdarkly.sdk.server.LDClient;
class Test {
public void a() {
LDClient client = new LDClient("sdk-key");
LDUser user = new LDUser.Builder("user-key")
.name("user")
.build();
/*~~>*/boolean flagValue = client.boolVariation("flag-key-123abc", user, false);
if (flagValue) {
// Application code to show the feature
} else {
// The code to run if the feature is off
}
}
}
SDK v6.x
Before:
import com.launchdarkly.sdk.LDContext;
import com.launchdarkly.sdk.server.LDClient;
class Test {
public void a() {
LDClient client = new LDClient("sdk-key");
LDContext context = LDContext.builder("context-key")
.name("user")
.build();
boolean flagValue = client.boolVariation("flag-key-123abc", context, false);
if (flagValue) {
// Application code to show the feature
} else {
// The code to run if the feature is off
}
}
}
After:
import com.launchdarkly.sdk.LDContext;
import com.launchdarkly.sdk.server.LDClient;
class Test {
public void a() {
LDClient client = new LDClient("sdk-key");
LDContext context = LDContext.builder("context-key")
.name("user")
.build();
/*~~>*/boolean flagValue = client.boolVariation("flag-key-123abc", context, false);
if (flagValue) {
// Application code to show the feature
} else {
// The code to run if the feature is off
}
}
}
Not sure if we should do this as part of this or another issue, but also handling when the flag key is in a local constant. For the non-local constant, that would require the recipe pipelines feature.
Parameters:
SDK v5.x
Before:
After:
SDK v6.x
Before:
After:
Should handle