Hi Adithyank

> On 16 May 2018, at 12.52, adithyank <[email protected]> wrote:
> 
> Hi Mario Garcia,
> 
> Groovy already has Map coercion feature with which the methods of any class
> can be delegated to the closures in Map. This uses `as` keyword.
> 

> If we implement `asType(Class)` in `ConfigObject` (ConfigObject already
> implements Map), some of the functionalities of existing coercion may be
> affected. I am not sure !

Using "as <classname>" already works, so there's already a pretty simple way to 
do what you're suggesting:

ConfigObject co = new ConfigSlurper().parse("""
myownconfig {
    name = 'Threadpool'
    displayLabel = "Thread Pool"
    threadCount = 12
}""")

public class MyConfig
{
     String name
     String displayLabel
     int threadCount
}

def myConfig = co.myownconfig as MyConfig

println "${myConfig.displayLabel} - ${myConfig.threadCount}"

(try it in Groovy Console)

-Jesper

Reply via email to