ProAnswers.org

can i do operator overloading in java?

2 Likes

NO. you can’t.

There were two major reasons why operator overloading wasn’t allowed in Java: “cleanliness” and VM complexity.

Operator overloading, while useful, can be exceedingly confusing, much more so than method overloading. Given the human tendency to assign specific meanings to single symbols, it is hard to get programmers to wrap their heads around multiple meanings for operators. What this means is that there is a marked increase in programming errors when a language supports operator overloading. Since practically the same benefit can be obtained via methods, the Java designers decided that the increased programmer mistake rate was not worth supporting operator overloading.

From a VM design standpoint, supporting operator overloading is considerably more difficult than method overloading, requiring a more complex VM. In addition, operator overloading generally will produce a slower VM than one which doesn’t support it, mostly due to the extra checks that operator overloading requires inside the VM.

source:wiki.answers