Overloading Operators
We'll cover the following...
Need for operator overloading
Traditionally we use operators on numeric types to create expressions, for example, or . Operator overloading is a feature where the language extends the capability to use operators on user-defined data types.
Compare the two lines in the following code snippet:
bigInteger1.multiply(bigInteger2)
bigInteger1 * bigInteger2
The first line uses the multiply
method from the JDK. The second line uses the *
operator on the instances of BigInteger
; ...