PlusEquals?

Per Nyfelt <[email protected]> Sun, 27 Oct 2024 19:02:09 +0100
Newsgroups gmane.comp.lang.groovy.user
Organization Alipsa HB
Message-ID <[email protected]>
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