No operator overloading in Java

Source: Internet
Author: User
Tags class definition
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.