0

I've created a Vector class and want to add be able to add the Vector's X and Y by just doing

Vector a + Vector b

Is it possible to do this in Java?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

1 Answers1

1

Sorry, but you cannot define or overload operators in Java. Implement an add method. You can have the add method return this, to allow chaining of operations (e.g., sum = a.add(b).add(c)), but that does not always result in the most readable code.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521