In Java, since there is no operator overload, then what is its replacement implementation ...
I'll help him answer.
Satisfactory answer
2011-04-22 13:43
In fact, is the string operation of the + and + +. However, you cannot customize operator overloading, so only this is overloaded. Its substitution implementation is actually the method (function). For example, the BigDecimal class, which can be used to represent a very long decimal number, is added without overloading the + number and directly has a member function called Add (BigDecimal) to implement.
4| Reviews (1)
Ask for help to know friends
timeslot | Current Category: 12 rank: 2770
Excel in Java Related: 12 rank: 2770
The questioner's assessment of the answer:
Thank you for your advice.
Sort By default | Sort by Time
Other Answer Total 2 article
Prosecutor |2011-04-22 13:04loveouyoko| Current category: 21 Rank: 44
Each language has the characteristics of each language, and operator overloading is not a feature of Java support, and there is no requirement that an alternative implementation be required.
Just as Java does not yet support closures, operator overloading does not replace implementations.
For object-oriented languages, the operators themselves are not "object-oriented," and everything can be done with methods
Basic attitude
For C + +, the beginning is starting from C, originally called the band Class C, and C compatibility in many design decisions played a lot of role. In type design, performance in the type to maintain a compatible C, although with class, but still retain the struct, the decisive reason is compatibility. Java was originally designed in an object-oriented language designed to learn from the C,c++,smalltalk, but did not maintain upward compatibility, with a new language posture appeared. In the end, C + + maintained the compatibility with the basic type in the processing of class, so that class behaved like a basic type. A class definition, like the basic type, is a set of data entities, with the introduction of an operator reload mechanism that allows class to be +-*/like a basic type .... Java uses a different direction for class, distinct from the basic type, and without operator overloading. A new indirect layer is introduced for the object, and the object of each class is a reference. This design on the one hand to the management of memory to the garbage collector, on the other hand, when the container is implemented, all objects can be treated uniformly, the introduction of the indirect layer has raised the abstraction level, at the same time brings the indirect cost of access.