As far as I know, there is almost no any language that allows a kind of syntax like that.
If we interpret
flag == null || false in English like you would have expected, it would have meant “flag is null or false”. Here, “is” actually refers to “belongs to one of” instead of “equals”, because “flag” only has one value, while “null or false” has at least two values (unless you expect the compiler to evaluate
(null || false), which doesn’t have compatible types).
In Kotlin, “belongs to one of” is called
in rather than
==, and “or” should be implemented as a set of multiple possible values rather than a boolean operator, so you could actually write this:
if (flag in setOf(null, false))
Although this is not the most efficient way to do this (not sure if the compiler could optimize
in setOf into two simple conditions without allocating an extra Set object), this is intuitive and does exactly what you want.