Java and operator overloading.

osfameron on 2005-05-03T09:41:41

It bemuses me that Java guru Joshua Bloch is still anti operator overloading ("Java Puzzlers" webcast from Javapolis, with Neal Gafter).

So if (a > b) is apparently more confusing than if (a.compareTo(b) > 0)? I totally get that arbitrary overloading isn't very javalike, but allowing specific operators (.compareTo overloads comparison ops, .addTo overloads + etc.) for classes tagged with particular interfaces doesn't seem that much of a mess. Hey ho.


These aren't the operators you're looking for

djberg96 on 2005-05-03T16:05:52

Like most Java droids, he read somewhere that operator overloading was evil and is now spewing the party line like a good little toadie.

The belief that operator overloading is evil stems largely from abuse by the C++ crowd. However, Ruby has shown me that it can be extremely useful without being the least bit confusing.

Re:

Aristotle on 2005-05-03T16:23:47

OTOH you can also abuse it in Ruby. (And Perl.)

It’s just very much like Java to be sternly patriarchal about things that could potentially be harmful. “No multiple inheritance for you! No operator overloading for you! No inheriting from base type classes for you!” Etc.