Net-informations.com
SiteMap  | About    

Why does Java not support operator overloading?

Java doesn't "need" operator overloading because it's just a choice made by its creators who wanted to keep the language more simple. Unlike C++ , Java doesn't support operator overloading. Every operator has a good meaning with its arithmetic operation it performs. Operator overloading allows you to do something extra than what for it is expected for. Java only allows arithmetic operations on elementary numeric types. If you allow developer to do operator overloading they will come up with multiple meanings for same operator which will make the learning curve of any developer hard and things more confusing and messing. The Java designers wanted to prevent people from using operators in a confusing manner, but it was not worth it. By avoiding operator overloading, it's more transparent which function is called when.

Operator overloading was never universally thought to be a bad idea in C++ programming language. C++ has both stack allocation and heap allocation and you must overload your operators to handle all situations and not cause memory leaks. Avoiding operator overloading in Java made the implementation and specification of Java a little simpler and it forced developers to not abuse operators. There has been some debate in the Java community about introducing operator overloading.









net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.