Tuesday, December 3, 2013

Operator Overloading in Scala

Does Scala support Operator Overloading?

If I go by below definition then I would say yes it does.
In object-oriented programming, operator overloading—less commonly known as operator ad hoc polymorphism—is a specific case of polymorphism, where different operators have different implementations depending on their arguments. Operator overloading is generally defined by the language, the programmer, or both.
Below is an example which elaborates on how is this supported. I am extending  binary <, unary pre negation (-) and unary post ++ operator for a custom datatype Rational.

No comments:

Post a Comment