Bird
0
0

A developer wrote this code to check a feature flag:

medium📝 Debug Q7 of 15
Spring Boot - Advanced Patterns
A developer wrote this code to check a feature flag:
if (featureFlagService.isFeatureEnabled("newUI") == true) {
// show new UI
}

What is a better way to write this condition in Java?
Aif (featureFlagService.isFeatureEnabled("newUI")) { ... }
Bif (featureFlagService.isFeatureEnabled("newUI") = true) { ... }
Cif (featureFlagService.isFeatureEnabled("newUI") != false) { ... }
Dif (featureFlagService.isFeatureEnabled("newUI") == false) { ... }
Step-by-Step Solution
Solution:
  1. Step 1: Identify redundant comparison

    Comparing boolean to true is unnecessary and verbose.
  2. Step 2: Simplify condition

    Use the boolean expression directly in if condition as in if (featureFlagService.isFeatureEnabled("newUI")) { ... }.
  3. Final Answer:

    if (featureFlagService.isFeatureEnabled("newUI")) { ... } -> Option A
  4. Quick Check:

    Boolean expressions don't need == true [OK]
Quick Trick: Use boolean directly, avoid == true comparisons [OK]
Common Mistakes:
  • Using assignment (=) instead of comparison (==)
  • Comparing to false when true is needed
  • Overcomplicating boolean checks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes