Quantcast
Channel: How to change behaviour of the method in groovy using that method in metaclass - Stack Overflow
Browsing latest articles
Browse All 3 View Live

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 Article



Answer 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 Article

How 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
Browsing latest articles
Browse All 3 View Live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>