Groovy way to dynamically instantiate a class from String

前端 未结 2 1994
滥情空心
滥情空心 2021-01-01 11:27

The answers of this question about the Groovy way to dynamically invoke a static method were very helpful but I\'m having trouble with the following case:

I defined

2条回答
  •  旧时难觅i
    2021-01-01 11:52

    This works, using the underlying GroovyClassLoader:

    def instance = this.class.classLoader.loadClass( 'Item', true, false )?.newInstance()
    

提交回复
热议问题