Why Kotlin does not support overloading of the assignment operator "="?

A valid use case is creating cleaner DSL-s.
For example, I have a Json DSL, but now I use += for assignment:

val json = jsonObject {
   "field" += 1
}

It would be much cleaner to use assignment. Or to be able to create other operators (same way in Scala), for example for β€œ:”. :wink:

But making the assignment overloadable is so minor restriction which would give little, but would cause deeply hidden bugs. So I am content with it.

PS: By the way, the assignment (opposite to Java) is not an operator, but a statement. So operator overloading is meaningless.

2 Likes