Kotlin elvis operator vs "... == true" boolean expression check preformance

371 views Asked by At

Assume we have nullable val a: Boolean?.

In code we want to assign value of a to another non-nullable variable val b: Boolean.

If a is true then we want b also to be true

If a is false or null the we want b to be false.

We can do this in 2 ways:

b = a ?: false

or

b = a == true

Which of the following approaches is better in terms of performance?

0

There are 0 answers