Groovy web console

subscribe to the feed Subscribe
to this
site

Trackable

Published 2 months ago by Alex
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
class Test implements Trackable {
    Integer num
    static EVENT_NAME = 'TestEvent'

    Test(num) {
        this.num = num
    }

    def name() {
        this.EVENT_NAME
    }

    
}

trait Trackable {
    def getEventProperties() {
        Class.forName(this.EVENT_NAME).newInstance(this)
    }
}

class TestEvent {

    Test test
    TestEvent(Test test) {
        this.test = test
    }

    def doubleIt() {
        this.test.num * 2
    }
}

def x = new Test(2)
x.getEventProperties().doubleIt()