Is there a way to add constructors using Groovy 2.0 Extensions -
in older (1.x.x) versions of groovy can add constructors using metaclass.constructor
example.metaclass.constructor << { string arg0 -> new example(arg0, "") }
is there way register constructors using new groovy 2.0 extension modules?
this seems work:
define extension class normal groovy 2 , add constructors in static initialiser
public class examplehelper { static { example.metaclass.constructor << { string arg0 -> new example(arg0, "") } } }
not know of...
you add static factory method example class ie:
class exampleextensionstatic { public static example newinstance( example type, string arg0 ) { new example( arg0, '' ) } }
then (after adding link class in staticextensionclasses
field of org.codehaus.groovy.runtime.extensionmodule
file), do:
example.newinstance( 'arg0' )
this worth asking on mailing list see if constructors worth adding module extension system.
Comments
Post a Comment