Recently, I've been learning a bit more of C++ and the dangers and uses of operator overloading, and the readability boost it provides to arithmetic types (like Complex numbers).
A while ago, I was playing around with Rust, and I really liked how they handled operator overloading, that is, via Traits in the std::ops
crate. So, having:
struct Fraction {
numerator: i32,
denominator: i32,
}
impl Add for Fraction { /* ... */ }
Ends up overloading the +
operator. This leads me to wonder the subject of the title...
Can Java implement a limited set of operator overloading via Interfaces? The compiler could check if the caller class implements the interface for a given operator, and change the operator to a method call (thus, it all being syntax sugar) or fail compiling otherwise.
Would this imply breaking changes for code compiled in older versions? Anyone know if this has been already discussed in mailings list, or a JEP proposed?