groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Theodorou <blackd...@gmx.org>
Subject Re: static propertyMissing in an interface
Date Sun, 03 Apr 2016 20:29:18 GMT
On 03.04.2016 17:33, OC wrote:
[...]
> ===
> 6 /tmp> <q.groovy
> class q {
>   static main(av) {
>     ExpandoMetaClass.enableGlobally()
>     Root.metaClass.static.propertyMissing={ name ->
>       String getter="get${name.capitalize()}"
>       def body={-> "<$name in $delegate>" }
>       delegate.metaClass.static."$getter"=body
>       body.call() // same problem with body(); delegate."$getter"() would work though
>     }
>     println "- ${Root.weird}"
>   }
> }
> interface Root {}
> 7 /tmp> groovy q.groovy
> Caught: groovy.lang.MissingMethodException: No signature of method: java.io.StringWriter.capitalize()
is applicable for argument types: () values: []
> groovy.lang.MissingMethodException: No signature of method: java.io.StringWriter.capitalize()
is applicable for argument types: () values: []
> 	at q$_main_closure1.doCall(q.groovy:5)
> 	at q.main(q.groovy:10)
> 8 /tmp>

so I misunderstood... it was not, that somehow body was not recognized 
as closure or such, it is that the execution of  code inside fails. 
capitalize() is a method on CharSequence, StringWriter is no 
CharSequence, so the call fails. Did you add such a method yourself? if 
not, you need to convert to String first.

bye Jochen


Mime
View raw message