Java doesn't allow operator overloading yet + is overloaded for class String. Is it possible to overload operators? Why doesn't Java allow operator overloading?

Byron Tymvios

It is true that Java does not allow operator overloading. It is also true that an exception was made for String, although this is out of the control of developers as it is a built in feature of Java. Developers have no control over operator overloading in Java.

The designers of Java wanted to keep Java simple and found that operator overloading made code more complex and difficult to read. There are other methods available to achieve the same functionality as operator overloading, you could create methods in a class named plus(), minus(), multiply(), etc...

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact