Kotlin suppress 'condition is always true'

Viewed 9159

Wasting more time scouring through the COUNTLESS number of inspections (which I know how to enable and disable), I cannot find ANY way to disable the particular inspection of 'Condition is always true' for my Kotlin (not Java) file in Android Studio. I know what I'm doing and don't need this inspection AT ALL, but more appropriately, I'd like to suppress it for the file or class or function or ANYTHING.

Incredibly frustrating, as always.

//I'm well aware the condition below is ALWAYS true
if(ANDROID_IS_AWESOME) {
    fml()
}
6 Answers

In Kotlin, use ConstantConditionIfto ignore this warning :

@Suppress("ConstantConditionIf")
if(ANDROID_IS_AWESOME) {
    fml()
}

This is how you would do it in Java :

@SuppressWarnings("ConstantConditions") // Add this line
public int foo() {
    boolean ok = true;
    if (ok) // No more warning here
        ...
}

In Kotlin I think you have to use @Suppress("SENSELESS_COMPARISON") instead.

In Kotlin, We can use @Suppress("SENSELESS_COMPARISON") for a class or if statement.

Related