Why is operator overloading not supported by java?


When a class has two or more methods by the same name but different parameters, at the time of calling based on the parameters passed respective method is called (or respective method body will be bonded with the calling line dynamically). This mechanism is known as method overloading.

Operator overloading

Operator overloading is the ability to redefine the functionality of the operators. Programming languages like c++ supports operator overloading.

you can redefine or overload most of the built-in operators available in C++. Thus, a programmer can use operators with user-defined types as well.

Overloaded operators are functions with special names: the keyword "operator" followed by the symbol for the operator being defined. Like any other function, an overloaded operator has a return type and a parameter list.

Java does not support operator overloading due to the following reasons −

  • Makes code complex − In case of operator overloading the compiler and interpreter (JVM) in Java need to put an extra effort to know the actual functionality of the operator used in a statement.
  • Programming error − Custom definition for the operators creates confusion for the programmers especially the new developers. Moreover, while working with programming languages that support operator overloading the program error rate is high compared to others.
  • Easy to develop tools like IDEs − Removal of operator overloading concept keeps the language simple for handling and process leading to a number of Integrated development environment in Java.
  • Method overloading − The functionality of operator overloading can be achieved in Java using method overloading in Java in a simple, error free and clear manner.

Updated on: 30-Jul-2019

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements