Hi,

Is it possible to override plus equals  (+=)  for a class?

I have a class the is want plus to be immutable and plusEquals to be mutable e.g:

def newMatrix = myMatrix + additionalRows

assert myObj == myMatrix - additionalRows

myMatrix += additionalRows

assert myMatrix == newMatrix

Since my implementation of plus involves cloning myMatrix which in my case is expensive, it would be a big difference if I could avoid that when there is no need. However +=  is calling plus and then assigning the result under the covers. Is there a way to "get to it" to override?

Best regards,

Per

Reply via email to