What if the plus sign you use every day was actually a secret function you could customize?
Why operators are functions in Kotlin - The Real Reasons
Imagine you want to add two custom objects, like two points on a map, by writing code that just adds them with a plus sign.
Without operators as functions, you must write separate methods and call them explicitly, making your code long and hard to read.
Manually calling methods like point1.add(point2) everywhere is slow to write and clutters your code.
It's easy to make mistakes or forget to call the right method, and your code looks less like natural math.
Kotlin treats operators like + as special functions you can define for your own types.
This means you can write point1 + point2 and Kotlin calls your function behind the scenes, making code clean and intuitive.
val result = point1.add(point2)
val result = point1 + point2
This lets you write code that reads like natural math or language, making it easier to understand and maintain.
For example, in a game, you can add two vectors with vector1 + vector2 instead of calling a method, making your game logic clearer and simpler.
Operators in Kotlin are actually functions you can define.
This makes code shorter, clearer, and less error-prone.
You can use natural symbols like + with your own types.