Disclaimer: I’ve never learned or used Groovy.
Having a quick look at the Javadoc of the Expando
class I can deduce that what happens in something similar to what Kotlin does with extension functions, that is that the compiler maps each extension function to a static function with an additional argument being the receiver.
So what (I think) the Groovy compiler does is that it maps each property access of a class extending Expando
to a getProperty()
/setProperty()
call, for instance:
expandoClass.lastName = "Smith"
gets translated to expandoClass.setProperty("lastName", "Smith")
and
println expandoClass.lastName
gets translated to println expandoClass.getProperty("firstName")
This means that the JVM really doesn’t support this feature.