Answer by Ted Naleid for How to change behaviour of the method in groovy...
The groovy idiomatic way is to save a reference to the old method and invoke it inside the new one. def oldPlus = Integer.metaClass.getMetaMethod("plus", [Integer] as Class[])Integer.metaClass.plus = {...
View ArticleAnswer by Kartik Shah for How to change behaviour of the method in groovy...
Use this to "spoil" plus method: Integer.metaClass.plus {Integer n -> delegate - (-n) - (-1)}assert 2+2 == 5Not surprisingly, using '+' operator in overloading plus method will result in...
View ArticleHow to change behaviour of the method in groovy using that method in metaclass
I would like to "spoil" plus method in Groovy in the following way:Integer.metaClass.plus {Integer n -> delegate + n + 1}assert 2+2 == 5I am getting StackOverflowException (which is not surprising)....
View Article