Groovy web console

subscribe to the feed Subscribe
to this
site
traitWith (via #groovywebconsole)
tweet this snippet Tweet
this
script

traitWith

Published 2 months ago by markhu with tags trait with bug
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
trait aTrait {
    def k = "traitVal"
    def m = [k:"memberVal"]
    void inTrait() {
      println "map m:${m}"
      println "bare   k:${k}"
      m.with {
        println "m.with k:${k} in Groovy ${GroovySystem.version}"
        }
    }
}

class aClass implements aTrait {}

def c = new aClass()
c.inTrait()