I think that there is something like this in C/C++, but what about in java? Can I add a method that will add two of them together, but instead of doing say obj1.add(obj2)
you can do obj1 + obj2
? Can you do the same for -, *, /, and == & other comparatives? Can you create a primitive, or would that take modifying the JVM?
Asked
Active
Viewed 66 times
1

user2507230
- 562
- 1
- 3
- 12
-
no, you can't do that in java – nachokk Aug 15 '13 at 02:22
2 Answers
0
No you cannot. There is no operator overloading in Java. The only thing that comes close to an overloaded operator in Java is + which can concatenate strings and perform standard addition.

Kon
- 10,702
- 6
- 41
- 58