Groovy: println vs System.out.println with GroovyInterceptable -


why need use system.out.println instead of println when use groovyinterceptable?

for example if coding in groovy file can print console typing:

println "printing console" 

but if want print here:

class test implements groovyinterceptable {     def sum(integer x, integer y) { x + y }      def invokemethod(string name, args) {         system.out.println "invoke method $name args: $args"     } }  def test = new test() test?.sum(2,3) 

i have use system.out.println in method, or else stackoverflowerror. why?

update: @dan getz answer below know why happens groovyinterceptable class now. know if there other class implementations in groovy issue arise?

this because class test implements groovyinterceptable interface, according docs, is

used notify methods should intercepted through invokemethod mechanism of groovyobject.

this isn't methods have been defined on class. try:

test?.total(2,3) 

you'll see returns

invoke method total args: [2, 3]

the call println inside invokemethod understood call this.println, call sum be. this.println calls invokemethod again, because implemented groovyinterceptable, , on.

this wouldn't happen if didn't implement groovyinterceptable. example, running following code

class test {     def sum(integer x, integer y) {          println "let's sum!"         x + y     } }  def test = new test() test?.sum(2,3) 

will output

let's sum!


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -