How does inheritance work in groovy for closures? Is there anything special to be aware of? My application is to extend a plugin controller, that I need to leave alone should any updates come in for it.
How does inheritance work in groovy for closures? Is there anything special to be
Share
Closure inheritance doesn’t make much sense (in the way we tend to use them anyway). A closure in practice is an instance of the
Closureclass. If we created subclasses ofClosurethen we could subclass those, but we don’t. For example in controllers, we define actions as inline instances, e.g.These are treated like methods in that we can call
list(), but that’s just syntactic sugar forlist.call(), sincecall()is an instance method of theClosureclass.In Grails 2.0 the preferred approach to creating controller actions is to use methods, although closures are still supported for backwards compatibility. One of the primary reasons for this switch is to support overloading and overriding, which isn’t possible (or at least practical) with inline closures. You can define a closure instance in a subclass with the same name as a base class instance, but you can’t call
super.list()since it will result in aStackOverflowError