HelloCW
HelloCW

Reputation: 2245

Why do I get the warning hint "Simplify boolean expression" in Kotlin?

I use Kotlin in Android Studio 3.01, I get the following warning hint for the code if (isRegistered(mContext)==false ) in Code A.

How can I fix it? Thanks!

Warning Hint

Simplify boolean expression. This inspections reports boolean expressions that have parts which can be reduced to constants

Code A

public override fun onDestroy() {
        if (isRegistered(mContext)==false ) {
            if (isDebug()) {              
                openActivity(applicationContext, UIBuy::class.java)
            } else {
                openActivity(applicationContext, UIBuy::class.java)
            }
        }
        super.onDestroy()
    }

Upvotes: 1

Views: 1753

Answers (1)

s1m0nw1
s1m0nw1

Reputation: 81879

You can simply change it to

if(!isRegistered(mContext))

The IDE will even suggest to make this change for you.

Upvotes: 4

Related Questions