Search code examples
syntaxoperator-precedencekotlin

Reason for precedence of operators with a type on the right-hand side


Kotlin Grammar-Precedence: - gives the operator precedence table for Kotlin, including the operators with a type on the right-hand side, :, as and as?, which have precedence in between the multiplication and prefix operators.

Is there a reason for giving them that particular precedence? I can't offhand think of a situation where it would be necessary/advantageous; what am I missing?


Solution

  • We wanted to avoid parentheses in cases where something has to be cast and then added/checked for "in" etc