Software and Applications (non-game)
D-Day
Java Programming

Why java not support operator overloading?

535455

Top Answer
User Avatar
Wiki User
Answered
2012-03-04 05:13:11
2012-03-04 05:13:11

Maybe because Sun said so. We have to bear with so many other idiosyncrasies too. But I guess that comes with every language.

There were two major reasons why operator overloading wasn't allowed in Java: "cleanliness" and compiler complexity. The main reason was the first, a personal preference choice made by Java's creator, James Gosling.

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 Java compiler (e.g. javac) design standpoint, supporting operator overloading is considerably more difficult than method overloading, requiring a more complex compiler.

123
๐Ÿ˜‚
0
๐ŸŽƒ
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
User Avatar

Related Questions


Operator overloading refers to redefining what the mathematical operators (+-*/) do when applied to different objects. Java does not support operator overloading.



Java does not support user defined operator overloading.The operator '+' is overloaded in Java and can be used for adding both numbers and Strings.


Java does not support operator overloading because Sun deliberately omitted it, citing simplicity as the reason for omission.


Operator overloading is not possible in Java.


Java does not support operator overloading. Operator overloading is the scenario where you overload a particular operator to do something that it is not designed to do. Ex: if you make the operator "*" do addition or the operator "-" do multiplication, imagine the chaos that would ensue in your program. So the java designers blocked this feature of operator overloading.


Java does not support operator overloading. Operator overloading is the scenario where you overload a particular operator to do something that it is not designed to do. Ex: if you make the operator "*" do addition or the operator "-" do multiplication, imagine the chaos that would ensue in your program. So the java designers blocked this feature of operator overloading.


== == === === === === === === Some Body told me that operator overloading is not there because it violates the transparency of java.since there is no hiding of information in java it does support op overloading === === === === === === Pranab Kumar Rana Software Engineer..... === === === ===


Java does not support operator overloading. Operator overloading is the scenario where you overload a particular operator to do something that it is not designed to do. Ex: if you make the operator "*" do addition or the operator "-" do multiplication, imagine the chaos that would ensue in your program. So the java designers blocked this feature of operator overloading.


Java does not support object overriding. It does support operator overloading by means of the "+" symbol which is used for both numeric addition as well as string concatenation.


C does not support operator overloading. If you mean C++ operator overloading, it depends on exactly what you wanted to do. If you wanted to '+' to strings, then you could write: string operator+(string a, string b) { // do something }


Operator overloading was a feature of C++ that the Java language designers thought was too complicated and not useful enough to include.


There is no concept of operator overloading in java, at least it is not available to the developers. There are still instances of operator overloading as in the case of "+" operator. It is used both to perform arithmetic sum as well as concatenation of two strings. But one cannot impart additional functions to an existing operator as in the case of C++.


You cannot explicitly overload an operator in Java but by default the + symbol is overloaded. You can use it to add numeric values as well as concatenate strings.


Because it would create unnecessary complications and people might end up using operators to do things that they arent supposed to do.


Pressumably, the designers of Java thought this would lead to confusing code.


No, java does not support explicit operator overloading. You can use an operator only for its intended purpose. But the "+" operator is implicitly overloaded. It can be used to add two numbers as well as concatenate two strings. Apart from this operator all other operators can be used only for their specific purpose.


Difference between Java and C++ is that Java does not support pointers. Pointers are inherently insecure and troublesome. Since pointers do not exist in Java, neither does the -> operator. Some other C++ features are not found in Java. • Java does not include structures or unions because the class encompasses these other forms. It is redundant to include them. • Java does not support operator overloading. • Java does not include a pre-processor or support the pre-processor directives. • Java does not perform any automatic type conversions that result in a loss of precision. • All the code in a Java program is encapsulated within one or more classes. Therefore, Java does not have global variables or global functions. • Java does not support multiple inheritances. • Java does not support destructors, but rather, add the finalize() function. • Java does not have the delete operator. • The << and >> are not overloaded for I/O operations. • Java does not support templates.


Java does not support opperator overloading, so the answer to your question is: none.


Operator overloading involving vector types is not supported.


The concept of Operator Overloading is similar to Method Overloading, in that the meaning of a given operator symbol changes according to the context it is being used in. That is, the semantics of the operator symbol are flexible, rather than fixed.The idea behind Operator Overloading is to take a common symbol, and adjust it's meaning to something logical for contexts other than what it was originally restricted to.The arithmetic operators ( + - * / ) are good examples. Using Operator Overloading, I could define that 'SomeArray + SomeValue' means that I should add SomeValue to the end of the array SomeArray.In general, Operator Overloading is what is called 'syntactic sugar' - it makes things more readable. For instance, the equivalent way to do the above example via method calls would be: SomeArray.addToEnd(SomeValue)The major problem with Operator Overloading is that it depends on people having the exact same interpretation of what an operator would mean in the new context, which is difficult to assure. Going back to the above example, there is some ambiguity as to where 'SomeArray + SomeValue' would mean to add in SomeValue - should SomeValue be added to the start of the array, or the end of the array? The answer is not obvious, and one would have to go look through the overload definition. While this confusion is also possible with methods, properly named methods (i.e. using addToEnd() rather than just add() ) helps avoid this entirely.For this reason, Java does not support user-defined Operator Overloading. Java does support certain operator overloading in narrow contexts, but only those defined by the language itself. That is, the '+' sign is overloaded to allow for string concatenation. However, the designer of Java (James Gosling) decided that his preference was to avoid Operator Overloading completely due to his perception of a "clean" language.


There is no operator overloading in C. This is only a C++ thing.


No. Operator and/or function overloading is only a C++ thing.


Operator overloading allows us to provide new implementations for existing operators. Not all languages support operator overloading; C does not, but C++ does. All languages provide built-in operators, however these operators cannot cater for user-defined types (they only work on built-in types). Operator overloading allows us to add this (missing) functionality so we can operate upon user-defined types as intuitively as we can with built-in types. In languages that do not support operator overloading, user-defined functions can be used instead of operators, but they are much less intuitive.


Operator overloading means defining what the operators ie + - * / & | etc mean in terms of your object, by writing appropriate methods in the object's code. This is not permitted in java. Method overloading is using the same method name in methods with different paramters ie setSize(Dimension d) setSize(int height, int width)



Copyright ยฉ 2020 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.