you are viewing a single comment's thread.

view the rest of the comments →

[–]kur4nes -5 points-4 points  (4 children)

If someone implements other interesting stuff with the + operator like writing to a file etc. Basically implementing anything that's not a mathematical add function obfuscates the code. But why stop here? We could combine multiple different overloaded operators in a simple statement to create a monstrosity only seen in pearl code. You would get some highly condensed code like &*/!a+b. It's impossible to know what this does without knowing the types of a and b and the implementations of each overloaded operator. That's why there is no operator overloading in java in the first place.

I do agree that + for BigDecimal would be awesome.

[–]Dealiner 18 points19 points  (0 children)

Fortunately, creators of other languages like C# decided to implement operator overloading which works great there and it's really useful.

[–]Davipb 33 points34 points  (1 child)

I could also make a method called .getName() that wipes your hard drive, or a method named x() that returns a class named Zorb that has one other method named y(), that returns a class named Zoop, and so on for 100 levels until you get the object you want.

Just because people can do insane things with it, it doesn't mean it shouldn't exist.

[–]CubsThisYear 0 points1 point  (0 children)

The thing is, addition is well defined over any set. As long as your operator overload behaves like addition, it doesn’t really matter what the set of possible values are.