does kotlin not have single `&` and `|` boolea...
# announcements
f
does kotlin not have single
&
and
|
boolean operator?
👌 2
v
AFAIK
and
and
or
, but for Int
k
So a direct answer: no there are no real operators for this.
t
Those operators exist for Boolean but are expressed differently :
a & b
is
a and b
a | b
is
a or b
Note that there is also a
xor
operator. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html
a
f
I try to use it for 2 comparisons but it translates to Int's bitwise and/or
ok I have to put the 2 expressions between parenthesis
makes sense
can you clarify for me:
boolean and/or/xor boolean
has nothing to do with bitwise operators?
t
Yes, the link I shared is the documentation of the
Boolean
type.
and
,
or
and
xor
are all functions that return
Boolean
. Those are the equivalent for
&
and
|
.
f
thanks
i
These operators are probably coming in the future, there's already a KEEP for them: https://github.com/Kotlin/KEEP/blob/b971b87ce106d150826e47b96f9697dce11fe787/proposals/bitwise-operators.md
f
thanks
that's only for bitwise operators and not the logical and/or, right?
t
Yes, only for numeric types.
f
are the non-short-circuit logical operators not very popular?
I thought they can be quite useful
but I have no job experience
k
Very rarely used I'd say.
f
and this is why they were not added as operators? Or is there another reason behind this?
k
&
and
|
for booleans are very rarely used, and whether the bitwise operators are used often depends a lot on the domain you're programming in. There's been a lot of discussion about this in #language-proposals, Kotlin discussions and the Youtrack issue.