https://kotlinlang.org logo
#announcements
Title
# announcements
f

Florian

07/11/2019, 9:14 PM
does kotlin not have single
&
and
|
boolean operator?
👌 2
v

ValV

07/11/2019, 9:17 PM
AFAIK
and
and
or
, but for Int
k

karelpeeters

07/11/2019, 9:19 PM
So a direct answer: no there are no real operators for this.
t

tseisel

07/12/2019, 7:43 AM
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

Alexey Belkov [JB]

07/12/2019, 8:05 AM
f

Florian

07/12/2019, 10:00 AM
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

tseisel

07/12/2019, 10:27 AM
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

Florian

07/12/2019, 10:35 AM
thanks
i

Icaro Temponi

07/12/2019, 12:30 PM
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

Florian

07/12/2019, 1:00 PM
thanks
that's only for bitwise operators and not the logical and/or, right?
t

tseisel

07/12/2019, 1:01 PM
Yes, only for numeric types.
f

Florian

07/12/2019, 9:19 PM
are the non-short-circuit logical operators not very popular?
I thought they can be quite useful
but I have no job experience
k

karelpeeters

07/12/2019, 9:20 PM
Very rarely used I'd say.
f

Florian

07/13/2019, 9:35 AM
and this is why they were not added as operators? Or is there another reason behind this?
k

karelpeeters

07/13/2019, 1:57 PM
&
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.
11 Views