38
votes

How to write in Kotlin:

flags |= newFlag

Only what I have found is:

flags = flags or newFlag

Is there a build-in bitwise or operator with assignment?

1
Currently, there's no such operator - Andrey Breslav
@AndreyBreslav Are there any build-in functions for flags? Or should I define own? Btw. What was the reason to 'remove' such operator? (Since e.g. for Android development, it is quite useful.) - TN.
@TN., there's a feature request for that: youtrack.jetbrains.com/issue/KT-1440. In it's comments you can find an interesting discussion, explaining why bitwise assignments are missing, with code samples included. You can vote for this feature with "thumbs up" button, probably we'll have 'em implemented one day, who knows. - Jk1
@TN. There are no built-in bitwise functions besides standard and, or, not and xor. What functions for flags would you like to see? - Andrey Breslav
@AndreyBreslav For instance, '|=' (addFlags), '&=' (removeFlags) that are useful while manipulating with flags. (Android is full of flags:) - TN.

1 Answers

23
votes

There is no built in bitwise-or assignment operator in Kotlin (yet).