I’m working on a grails application atm. I need a property on an abstract java class (org.quartz.Trigger) adding
Trigger.metaClass.id = { delegate.hashCode() }
before I call the class works. I would like to enable this for all my Triggers in my application. Is this possible? Or do I have to repeat this everytime I need the property?
If you add to the
metaClassbefore anyTriggerobjects are instantiated, then this addition will exist in all of them.However, after they are created, you would need to add it to every instance of
Trigger.Of course, this method will only be visible from Groovy, as Java does not know about the
metaClass.Some example Groovy code showing this in action: