Groovy web console

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

dynamic class instantiation

Published 2 months ago by sild
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
class A {
    private String clos;

    A(String clsr) {
        clos = clsr;
    }
    String getClos() {
        return clos;
    }
}
def instance = this.class.classLoader.loadClass( 'A', true, false )?.newInstance([clos: "test"])
instance.getClos();