Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the costs of using ExpandoMetaClass.enableGlobally()? (Groovy)

Tags:

grails

groovy

I want to be sure I am not going to cause a performance issue with this. We are writing a simple Money DSL and I was advised to turn on:

ExpandoMetaClass.enableGlobally()

However, I cannot determine yet exactly what this means. Does it only enable metaclass overrides on the inheritance tree for the root object, or does it apply it to every object type in memory?

Are there risks to applying Expando globally to a production instance?

like image 761
Gr3go Avatar asked Oct 11 '25 15:10

Gr3go


1 Answers

Grails does this already, so whatever cost is involved is already incurred :)

This setting changes the default MetaClass implementation from MetaClassImpl to ExpandoMetaClass. ExpandoMetaClass was written by Graeme for Grails to make it easier to dynamically add methods to the metaclass, e.g.

String.metaClass.bark = { -> println "WOOF!" }

and it was added to Groovy core years ago.

like image 165
Burt Beckwith Avatar answered Oct 14 '25 09:10

Burt Beckwith